[英]Gradle error after upgrading to AndoidX the latest Android Gradle Plugin
After upgrading to the latest AndroidX libs & Android Gradle Plugin, when I run lint on my project, the lint build failed.升级到最新的 AndroidX 库和 Android Gradle 插件后,当我在我的项目上运行 lint 时,lint 构建失败。
It all started with the latest Android Gradle Plugin complaining that Program type already present:com.google.common.util.concurrent.ListenableFuture when building my project这一切都始于最新的 Android Gradle 插件抱怨程序类型已经存在:com.google.common.util.concurrent.ListenableFuture 在构建我的项目时
Below are the errors:以下是错误:
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:lint'.
> Could not resolve all artifacts for configuration ':app:debugAndroidTestRuntimeClasspath'.
> Could not resolve com.google.guava:guava:23.6-android.
Required by:
project :app
> Cannot find a version of 'com.google.guava:guava' that satisfies the version constraints:
Dependency path 'Code Base:app:unspecified' --> 'androidx.test.ext:truth:1.1.0' --> 'com.google.guava:guava:26.0-android'
Dependency path 'Code Base:app:unspecified' --> 'com.google.truth:truth:0.42' --> 'com.google.guava:guava:25.1-android'
Dependency path 'Code Base:app:unspecified' --> 'androidx.room:room-guava:2.1.0-alpha03' --> 'com.google.guava:guava:23.6-android'
Dependency path 'Code Base:app:unspecified' --> 'com.google.api-client:google-api-client:1.25.0' --> 'com.google.guava:guava:20.0'
Dependency path 'Code Base:app:unspecified' --> 'androidx.test.ext:truth:1.1.0' --> 'com.google.truth:truth:0.42' --> 'com.google.guava:guava:25.1-android'
Constraint path 'Code Base:app:unspecified' --> 'com.google.guava:guava' strictly '23.6-android' because of the following reason: debugRuntimeClasspath uses version 23.6-android
Constraint path 'Code Base:app:unspecified' --> 'com.google.guava:guava' strictly '23.6-android' because of the following reason: debugRuntimeClasspath uses version 23.6-android
Constraint path 'Code Base:app:unspecified' --> 'com.google.guava:guava' strictly '23.6-android' because of the following reason: debugRuntimeClasspath uses version 23.6-android
Constraint path 'Code Base:app:unspecified' --> 'com.google.guava:guava' strictly '23.6-android' because of the following reason: debugRuntimeClasspath uses version 23.6-android
> Could not resolve org.checkerframework:checker-compat-qual:2.0.0.
Required by:
project :app
> Cannot find a version of 'org.checkerframework:checker-compat-qual' that satisfies the version constraints:
Dependency path 'Code Base:app:unspecified' --> 'com.google.truth:truth:0.42' --> 'org.checkerframework:checker-compat-qual:2.5.3'
Dependency path 'Code Base:app:unspecified' --> 'androidx.test.ext:truth:1.1.0' --> 'com.google.guava:guava:26.0-android' --> 'org.checkerframework:checker-compat-qual:2.5.2'
Dependency path 'Code Base:app:unspecified' --> 'androidx.test.ext:truth:1.1.0' --> 'com.google.truth:truth:0.42' --> 'org.checkerframework:checker-compat-qual:2.5.3'
Constraint path 'Code Base:app:unspecified' --> 'org.checkerframework:checker-compat-qual' strictly '2.0.0' because of the following reason: debugRuntimeClasspath uses version 2.0.0
Constraint path 'Code Base:app:unspecified' --> 'org.checkerframework:checker-compat-qual' strictly '2.0.0' because of the following reason: debugRuntimeClasspath uses version 2.0.0
Constraint path 'Code Base:app:unspecified' --> 'org.checkerframework:checker-compat-qual' strictly '2.0.0' because of the following reason: debugRuntimeClasspath uses version 2.0.0
Constraint path 'Code Base:app:unspecified' --> 'org.checkerframework:checker-compat-qual' strictly '2.0.0' because of the following reason: debugRuntimeClasspath uses version 2.0.0
> Could not resolve com.google.errorprone:error_prone_annotations:2.1.3.
Required by:
project :app
I tried putting the following but it doesn't work:我尝试放置以下内容但它不起作用:
subprojects {
project.configurations.all {
exclude group: 'com.google.guava', module: 'failureaccess'
resolutionStrategy.eachDependency { details ->
if (details.requested.group == 'com.android.support'
&& !details.requested.name.contains('multidex') ) {
details.useVersion "26.1.0"
}
if('guava' == details.requested.name) {
details.useVersion '27.0-android'
}
}
}
}
May I know what the errors mean and how can I solve it?我可以知道错误的含义以及如何解决吗? Thanks.谢谢。
Check that you don't have duplicated dependencies for variants.检查您是否没有重复的变体依赖项。 For instance:例如:
implementation 'com.google.truth:truth:0.42'
...
androidTestImplementation 'com.google.truth:truth:0.42'
I was also trying to solve this, for me it's due to the new Google places library:我也试图解决这个问题,对我来说这是由于新的 Google 地点库:
implementation "com.google.android.libraries.places:places:1.0.0"
which was causing tests under androidTest
to fail.这导致androidTest
下的测试失败。
As a workaround, I added this to build.gradle
:作为一种解决方法,我将其添加到build.gradle
:
configurations {
androidTestImplementation.exclude module: 'guava'
androidTestImplementation.exclude module: 'error_prone_annotations'
androidTestImplementation.exclude module: 'checker-qual'
}
which fixes both lint and Android tests.它修复了 lint 和 Android 测试。 Not sure of the consequences yet though.虽然还不确定后果。
edit: In your case you might have to put checker-compat-qual
instead of checker-qual
编辑:在您的情况下,您可能必须放置checker-compat-qual
而不是checker-qual
change改变
details.useVersion '27.0-android'
to到
details.useVersion '23.6-android'
Because of error message Could not resolve com.google.guava:guava:23.6-android.
由于错误消息Could not resolve com.google.guava:guava:23.6-android.
tells it requires version 23.6-android
告诉它需要版本23.6-android
Put this on Build.gradle in app module把它放在应用模块的 Build.gradle 上
lintOptions {
checkReleaseBuilds false
abortOnError false
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.