Flutter版本升级后无法运行应用及依赖冲突解决咨询
问题描述
Flutter版本升级情况
原版本:
Flutter 3.3.1 • channel stable • https://github.com/flutter/flutter.git Framework • revision 4f9d92fbbd (10 months ago) • 2022-09-06 17:54:53 -0700 Engine • revision 3efdf03e73 Tools • Dart 2.18.0 • DevTools 2.15.0
新版本:
Flutter 3.10.5 • channel stable • https://github.com/flutter/flutter.git Framework • revision 796c8ef792 (5 weeks ago) • 2023-06-13 15:51:02 -0700 Engine • revision 45f6e00911 Tools • Dart 3.0.5 • DevTools 2.23.1
构建报错信息
* What went wrong: A problem occurred evaluating project ':app'. > No signature of method: build_58ywicibeljyvd9hmz1hf35px.android() is applicable for argument types: (build_58ywicibeljyvd9hmz1hf35px$_run_closure2) values: [build_58ywicibeljyvd9hmz1hf35px$_run_closure2@51a7d2a1]
依赖冲突情况
当前通过Git引入flutter_inappwebview:
flutter_inappwebview: git: url: https://github.com/rshrc/flutter_inappwebview ref: master
若使用常规版本引入,会出现以下版本冲突:
Because cred_components >=0.0.7 depends on hello_sign_plugin ^0.0.3 and no versions of hello_sign_plugin match >0.0.3 <0.1.0, cred_components >=0.0.7 requires hello_sign_plugin 0.0.3. And because hello_sign_plugin 0.0.3 depends on flutter_inappwebview ^6.0.0-beta.22, cred_components >=0.0.7 requires flutter_inappwebview ^6.0.0-beta.22. And because youtube_player_flutter 8.1.2 depends on flutter_inappwebview ^5.7.2+3 and no versions of youtube_player_flutter match >8.1.2 <9.0.0, cred_components >=0.0.7 is incompatible with youtube_player_flutter ^8.1.2. So, because dsaas depends on both youtube_player_flutter ^8.1.2 and cred_components ^0.0.7, version solving failed.
解决方案
1. 修复构建报错(Android配置问题)
这个报错多因Flutter升级后,Gradle插件/版本不匹配或build.gradle语法问题导致:
- 调整项目根目录
build.gradle的Gradle插件版本,Flutter 3.10.x推荐使用7.4.2+:dependencies { classpath 'com.android.tools.build:gradle:7.4.2' // 保留其他原有依赖 } - 修改
gradle/wrapper/gradle-wrapper.properties中的Gradle版本为7.5+:distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-bin.zip - 清理并重建项目:
flutter clean flutter pub get flutter build apk --debug
2. 解决依赖冲突
方案一:升级冲突依赖包
查看youtube_player_flutter是否有支持flutter_inappwebview 6.x的版本(如9.x系列),直接升级以兼容cred_components的依赖要求:
youtube_player_flutter: ^9.x.x # 替换为实际兼容的版本号
方案二:强制依赖覆盖
若无法升级youtube_player_flutter,可在pubspec.yaml末尾添加依赖覆盖,强制所有包使用兼容版本的flutter_inappwebview,需自行测试功能兼容性:
dependency_overrides: flutter_inappwebview: ^6.0.0-beta.22
执行flutter pub get后验证应用功能是否正常。
方案三:调整Git引入的依赖版本
将当前Git引入的flutter_inappwebview切换到与hello_sign_plugin匹配的版本,避免版本过高导致的冲突和构建问题:
flutter_inappwebview: git: url: https://github.com/rshrc/flutter_inappwebview ref: 6.0.0-beta.22 # 使用与hello_sign_plugin兼容的版本
方案四:替换冲突依赖
如果以上方案均不可行,可考虑替换其中一个冲突包:
- 更换为支持
flutter_inappwebview 6.x的视频播放插件替代youtube_player_flutter; - 联系
cred_components开发者,请求升级其依赖的hello_sign_plugin版本以支持更高版本的flutter_inappwebview。
内容的提问来源于stack exchange,提问作者Sunisha Guptan
相关产品推荐
相关产品推荐

