【问题标题】:How to fix 'android.arch.lifecycle:runtime' having different versions in compile time and runtime in Flutter?如何修复“android.arch.lifecycle:runtime”在 Flutter 中的编译时和运行时版本不同?
【发布时间】:2020-03-10 11:41:33
【问题描述】:

这是我第一次将 Flutter 应用与 Firebase 连接起来。我在 android -> app 目录下添加了 google-services.json 文件,然后

apply plugin: 'com.google.gms.google-services' 在我的 app:build.gradle

dependencies {
        [...]
        classpath 'com.google.gms:google-services:3.2.1'
    }

在我 android 目录下的 project:build.gradle 中,遵循此指导线https://codelabs.developers.google.com/codelabs/flutter-firebase/#6

当我运行项目时,我得到了这个错误

Launching lib\main.dart on POCO F1 in debug mode...
Initializing gradle...
Resolving dependencies...
Running Gradle task 'assembleDebug'...
registerResGeneratingTask is deprecated, use registerGeneratedResFolders(FileCollection)
registerResGeneratingTask is deprecated, use registerGeneratedResFolders(FileCollection)
registerResGeneratingTask is deprecated, use registerGeneratedResFolders(FileCollection)

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:preDebugBuild'.
> Android dependency 'android.arch.lifecycle:runtime' has different version for the compile (1.0.0) and runtime (1.1.1) classpath. You should manually set the same version via DependencyResolution

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 4s
Finished with error: Gradle task assembleDebug failed with exit code 1

运行 gradle build --stacktrace 后,gradle 建议将以下依赖项添加到我的 app:build.gradle 中,但它不起作用 p>

dependencies {
    implementation("android.arch.lifecycle:runtime:1.1.1")
    implementation("android.arch.lifecycle:common:1.1.1")
    implementation("android.arch.core:common:1.1.1")
}

【问题讨论】:

  • 尝试在 build.gradle 的末尾添加以下代码(在 android 文件夹内):subprojects { project.configurations.all { resolutionStrategy.eachDependency { details -> if (details.requested.group == 'com.android.support' && !details.requested.name.contains('multidex') ) { details.useVersion "{please input your build tools version here}" } } } }
  • 不要忘记在上面代码的最后一行更新你的构建工具版本。
  • 在我的 app:build.gradle 文件中,他们没有指定构建工具版本。你能告诉我如何找到
  • 我检查了我的 android->sdk->build-tools 文件夹,有 2 个文件夹分别命名为 28.0.3 和 29.0.2。我为这两个版本更改了这样details.useVersion "29.0.2" 的代码,但它给出了以下错误 -------------- Could not resolve all files for configuration ':app:debugCompileClasspath'. > Could not find com.android.support:support-v4:29.0.2.

标签: android gradle flutter


【解决方案1】:

我遇到了同样的问题。我通过添加解决了

 implementation "android.arch.lifecycle:extensions:1.1.1" 

android > app > build.gradle 文件并将我在 android > build.gradle 中的 google-services 升级到 4.2.0版

classpath 'com.google.gms:google-services:4.2.0'

【讨论】:

    猜你喜欢
    • 2020-03-12
    • 2020-03-17
    • 1970-01-01
    • 1970-01-01
    • 2017-11-23
    • 1970-01-01
    • 2016-11-24
    • 2019-01-31
    • 1970-01-01
    相关资源
    最近更新 更多