'androidx.lifecycle:lifecycle-runtime'具有不同的编译版本

时间:2019-10-30 13:24:14

标签: flutter

在同时使用2种依赖时,我遇到了问题,我在pubspec.yaml中使用了这种依赖。

dependencies:
  flutter:
    sdk: flutter
  location: ^2.3.5 .  ** this one
  image_picker: ^0.6.1+10 ** this one

如果使用这些依赖项,将显示下一个问题

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:preDebugBuild'.
> Android dependency 'androidx.core:core' has different version for the compile (1.0.0-rc01) and runtime (1.0.2) 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 2s
*******************************************************************************************
The Gradle failure may have been because of AndroidX incompatibilities in this Flutter app.
See goo.gl/CP92wY for more information on the problem and how to fix it.
*******************************************************************************************
Gradle task assembleDebug failed with exit code 1
Exited (sigterm)

但是,如果我使用这些依赖项之一,则效果很好,但是如果两者都在顶部出现相同的问题

这是

的代码
gradle.properties
android.useAndroidX=true
android.enableJetifier=true
org.gradle.jvmargs=-Xmx1536M

这是

的代码
build.gradle
buildscript {
    ext.kotlin_version = '1.2.71'
    repositories {
        google()
        jcenter()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:3.2.1'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }
}

allprojects {
    repositories {
        google()
        jcenter()
    }
}

rootProject.buildDir = '../build'
subprojects {
    project.buildDir = "${rootProject.buildDir}/${project.name}"
}
subprojects {
    project.evaluationDependsOn(':app')
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

修改 我试图将此包image_picker降级到0.6.1 + 1或更小,并且现在可以正常工作!但我想知道是否还有另一种定期修复方法?

1 个答案:

答案 0 :(得分:1)

我最近有一个类似的错误。 您只需要明确告诉编译器要使用哪个版本的依赖项即可。

那对我有用。

您可以重写项目级别build.gradle文件的这一部分:

subprojects {
    project.buildDir = "${rootProject.buildDir}/${project.name}"
}
subprojects {
    project.evaluationDependsOn(':app')
}

subprojects {
    project.buildDir = "${rootProject.buildDir}/${project.name}"
    project.evaluationDependsOn(':app')

    project.configurations.all {
        resolutionStrategy.eachDependency { details ->
           if (details.requested.group == 'androidx.core'
            && !details.requested.name.contains('multidex')) {
            details.useVersion "1.0.2"
        }
    }
}

我希望可以解决您的问题:)