You need to enable JavaScript to run this app.
最新活动
大模型
产品
解决方案
定价
生态与合作
支持与服务
开发者
了解我们

Flutter运行Android 28模拟器时依赖版本不一致报错求助

解决Flutter应用在Android 28模拟器上的依赖版本冲突问题

嘿,我之前也碰到过一模一样的问题!你的Flutter应用之前运行正常,但在Android 28的Pixel 2模拟器上抛出了Execution failed for task ':app:preDebugBuild'错误,核心原因就是com.android.support:support-core-utils的编译版本(27.1.1)和运行时版本(28.0.0-rc01)不匹配,咱们可以通过手动统一依赖版本来搞定它。

具体解决步骤:

  1. 打开你的Flutter项目,找到项目根目录下android文件夹里的build.gradle文件(不是app模块下的那个)。
  2. allprojects代码块中添加依赖版本强制统一的配置,修改后的代码如下:
allprojects {
    repositories {
        google()
        jcenter()
    }

    // 新增:强制统一support-core-utils版本
    configurations.all {
        resolutionStrategy {
            force 'com.android.support:support-core-utils:28.0.0'
        }
    }
}
  1. 保存文件后,执行flutter clean清理项目缓存,然后重新运行你的应用。

为什么这个方法有效?

这段配置会告诉Gradle,不管项目里的哪个第三方依赖引入了不同版本的support-core-utils,都强制使用我们指定的28.0.0版本,这样就彻底解决了编译版本和运行时版本不一致的冲突问题。

另外,从你提供的flutter doctor检测结果来看,你的开发环境整体是没问题的:

/work/sdk/flutter/bin/flutter doctor --verbose
[✓] Flutter (Channel stable, v1.0.0, on Mac OS X 10.14.3 18D109, locale en-BE)
• Flutter version 1.0.0 at /work/sdk/flutter
• Framework revision 5391447fae (3 months ago), 2018-11-29 19:41:26 -0800
• Engine revision 7375a0f414
• Dart version 2.1.0 (build 2.1.0-dev.9.4 f9ebf21297)
[✓] Android toolchain - develop for Android devices (Android SDK 28.0.3)
• Android SDK at /work/sdk/Android
• Android NDK location not configured (optional; useful for native profiling support)
• Platform android-28, build-tools 28.0.3
• ANDROID_HOME = /work/sdk/Android
• Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
• Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1248-b01)
• All Android licenses accepted.
[✓] iOS toolchain - develop for iOS devices (Xcode 10.1)
• Xcode at /Applications/Xcode.app/Contents/Developer
• Xcode 10.1, Build version 10B61
• ios-deploy 1.9.4
• CocoaPods version 1.6.0
[✓] Android Studio (version 3.3)
• Android Studio at /Applications/Android Studio.app/Contents
• Flutter plugin version 33.0.1
• Dart plugin version 182.5215
• Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1248-b01)
[!] IntelliJ IDEA Ultimate Edition (version 2018.3.4)
• IntelliJ at /Applications/IntelliJ IDEA.app
✗ Flutter plugin not installed; this adds Flutter specific functionality.
✗ Dart plugin not installed; this adds Dart specific functionality.
[✓] Connected device (1 available)
• Android SDK built for x86
• emulator-5554
• android-x86
• Android 9 (API 28) (emulator)
! Doctor found issues in 1 category.

唯一的小问题是IntelliJ没装Flutter和Dart插件,但这和当前的依赖冲突问题无关,如果你平时用IntelliJ开发的话再去安装就行。

内容的提问来源于stack exchange,提问作者ccc

火山引擎 最新活动