HarmonyOS鸿蒙Next中flutter根据官方文档配置鸿蒙版pigeon加载失败

HarmonyOS鸿蒙Next中flutter根据官方文档配置鸿蒙版pigeon加载失败 flutter版本:3.27.5-ohos-1.0.2

依据官方文档配置pigeon鸿蒙版(https://gitcode.com/openharmony-tpc/flutter_packages/tree/br_pigeon-v25.3.2_ohos/packages/pigeon)

dependencies:    
    pigeon:
        git:
            url: "https://gitcode.com/openharmony-sig/flutter_packages.git"
            path: "packages/pigeon"
            ref: "br_pigeon-v25.3.2_ohos"

pub get时报错:

Package not available (the pubspec for pigeon 25.5.0 from git has version 11.0.1).
Failed to update packages.

请问要如何修复?


更多关于HarmonyOS鸿蒙Next中flutter根据官方文档配置鸿蒙版pigeon加载失败的实战教程也可以访问 https://www.itying.com/category-92-b0.html

3 回复

开发者你好

本地测试:

flutter doctor -v

Flutter (Channel [user-branch], 3.27.5-ohos-1.0.2

flutter pub get

Resolving dependencies...

Downloading packages...

Got dependencies!

27 packages have newer versions incompatible with dependency constraints.

依赖文件:

dependencies:

  flutter:
    sdk: flutter

  pigeon:
    git:
      url: "https://gitcode.com/openharmony-sig/flutter_packages.git"
      path: "packages/pigeon"
      ref: "br_pigeon-v25.3.2_ohos"
      depth: 1

本地测试可以正常获取,尝试清理 pub 缓存,是否可以正常,清除缓存后,关闭终端或者IDE后重新执行flutter pub get。

如果还不行,提供下flutter doctor -v,以及在flutter_flutter仓库是否是https://gitcode.com/openharmony-tpc/flutter_flutter,以及分支是否正确。

更多关于HarmonyOS鸿蒙Next中flutter根据官方文档配置鸿蒙版pigeon加载失败的实战系列教程也可以访问 https://www.itying.com/category-92-b0.html


鸿蒙Next中Flutter配置Pigeon失败,通常因依赖版本不匹配或配置错误导致。检查Flutter与Pigeon插件版本是否兼容鸿蒙环境,确保pubspec.yaml中pigeon依赖项正确。验证鸿蒙工程配置,确认Flutter插件已正确集成。

这个问题是由于依赖版本声明冲突导致的。在你的 pubspec.yaml 中,你指定了 pigeon 包,但未指定版本号。Flutter 工具在解析时,可能从其他依赖(如 flutter SDK)的约束中推断出需要 pigeon ^25.5.0,而你从 Git 仓库拉取的 br_pigeon-v25.3.2_ohos 分支,其 pubspec.yaml 中声明的版本是 11.0.1。这导致了版本不匹配错误。

要解决此问题,你需要在 pubspec.yaml 中为 pigeon 依赖明确指定一个与 Git 分支版本兼容的版本号。根据错误信息和分支名称,你应该将依赖声明修改为:

dependencies:
  pigeon: ^11.0.1
    git:
      url: "https://gitcode.com/openharmony-sig/flutter_packages.git"
      path: "packages/pigeon"
      ref: "br_pigeon-v25.3.2_ohos"

关键修改是添加了 ^11.0.1 版本约束,这与你拉取的分支中 pubspec.yaml 声明的 11.0.1 版本一致。这样,Flutter 的包管理器在解析时,版本要求就匹配了。

修改后,执行 flutter clean 清理缓存,再重新运行 flutter pub get 即可。

回到顶部