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

问题描述 投票:1回答:1

当我同时使用两个依赖项时遇到问题,我正在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或更小,并且现在可以正常工作!但我想知道是否还有另一种定期修复方法?

当我同时使用2个依赖项时遇到问题,我在pubspec.yaml依赖项中使用了这种依赖项:flutter:sdk:flutter位置:^ 2.3.5。 **这个图像选择器:^ 0.6.1 + ...

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

这对我有用。

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

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

as

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"
        }
    }
}

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

flutter
1个回答
0
投票

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

© www.soinside.com 2019 - 2024. All rights reserved.