【问题标题】:Flutter & AndroidX incompatibility How to set a dependency manuallyFlutter & AndroidX 不兼容如何手动设置依赖
【发布时间】:2019-10-22 23:52:52
【问题描述】:

由于 AndroidX 不兼容,我在编译时遇到错误:

Android 依赖 'androidx.vectordrawable:vectordrawable' 对于编译 (1.0.0) 和运行时 (1.0.1) 类路径有不同的版本。您应该通过 DependencyResolution 手动设置相同的版本

-> this post <- 之后,我在 build.gradle 中添加了一些代码

allprojects {

configurations.all {
    resolutionStrategy.force"androidx.vectordrawable:vectordrawable:1.0.0",
}
repositories {
    google()
    jcenter()
}

下一次运行给了我另一个错误

Android 依赖 'androidx.core:core' 对于编译 (1.0.0) 和运行时 (1.0.1) 类路径有不同的版本。您应该通过 DependencyResolution 手动设置相同的版本

我尝试添加这个

"androidx.vectordrawable:vectordrawable:1.0.0","androidx.core:core:1.0.0",

但我可能做错了,因为我得到了经典的“意外 bla bla bla”

有什么建议吗?

提前致谢

[edit] 我也试过这个老把戏,但没用 (还根据需要降级软件包HERE

rootProject.allprojects {
    project.configurations.all {
        resolutionStrategy.eachDependency { details ->
            if (details.requested.group == 'androidx.core') {
                details.useVersion "1.0.1"
            }
            if (details.requested.group == 'androidx.lifecycle') {
                details.useVersion "2.0.0"
            }
            if (details.requested.group == 'androidx.versionedparcelable') {
                details.useVersion "1.0.0"
            }
        }
    }
}

现在返回一个不同的错误

Android 依赖 'androidx.appcompat:appcompat' 对于编译 (1.0.0) 和运行时 (1.0.2) 类路径有不同的版本。您应该通过 DependencyResolution 手动设置相同的版本

【问题讨论】:

标签: android gradle flutter dart androidx


【解决方案1】:
  1. 在 android/gradle/wrapper/gradle-wrapper.properties 中更改以 distributionUrl 开头的行,如下所示:distributionUrl=https://services.gradle.org/distributions/gradle-4.10.2-all.zip

2.在android/build.gradle中,替换:

dependencies {
    classpath 'com.android.tools.build:gradle:3.2.1'
}

通过

dependencies {
  classpath 'com.android.tools.build:gradle:3.3.0'
}

3.在android/gradle.properties中,追加

android.enableJetifier=true
android.useAndroidX=true

4.在android/app/build.gradle:

在 android { 下,确保 compileSdkVersion 和 targetSdkVersion 至少为 28。

5. 将所有已弃用的库替换为 AndroidX 等效项。例如,如果您使用默认的 .gradle 文件,请进行以下更改:

在android/app/build.gradle中

testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

通过

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

最后,在依赖项下替换

androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'

通过

androidTestImplementation 'androidx.test:runner:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'

【讨论】:

    【解决方案2】:

    您需要将此指示用于最新版本的... :)

    1)android/gradle/wrapper/gradle-wrapper.properties

    用最新的gradle替换以distributionUrl开头的行:

    > distributionUrl = https\://services.gradle.org/distributions/gradle-5.4.1-all.zip
    

    2)

    android/build.gradle

    你需要更换:

    > dependencies {
    >     classpath 'com.android.tools.build:**gradle:x.x.x**' }
    

    dependencies { classpath 'com.android.tools.build:**gradle:3.5.0**' }

    3) 在 android/gradle.properties 中粘贴这个

    android.enableJetifier=true android.useAndroidX=true

    4) 在 android/app/build.gradle 中:确保 compileSdkVersiontargetSdkVersion 至少为 28``

    最重要的是这里: 在android/app/build.gradle:替换

    testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    

    用`

    > testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    
    `
    

    替换

    > androidTestImplementation 'com.android.support.test:runner:x.x.x'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:x.x.x'
    

    > androidTestImplementation 'androidx.test:runner:1.1.1'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
    

    【讨论】:

    • 我也遇到了同样的问题,我已经按照你的指示做了,我什至和其他人一起尝试过,但是错误仍然存​​在,我不知道要改变什么,我不知道它是否会影响我有最新版本的颤振。 Execution failed for task ':simple_permissions:verifyReleaseResources@Messou
    【解决方案3】:

    始终确保新添加的依赖项与您的 gradle 版本相匹配, 您可能需要升级或降级依赖项以匹配您的 gradle 版本,但最重要的是,建议使用最新的 gradle 版本并将其与最新的插件依赖项匹配以避免这些错误。

    【讨论】:

      猜你喜欢
      • 2021-06-24
      • 1970-01-01
      • 2019-11-07
      • 1970-01-01
      • 2021-07-10
      • 2020-05-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多