【问题标题】:Android studio tends to use wrong version of Android Support Library,Android Studio 倾向于使用错误版本的 Android 支持库,
【发布时间】:2018-10-15 11:57:33
【问题描述】:

我的项目中使用的第三方库之一需要来自 Android 支持库的 recyclerview 包。由于我的build.gradle 是用compileSdVersion 28 设置的,所以必须使用28.0.0 版本的库。

到目前为止,我可以看到项目构建没有错误的唯一方法是在 build.gradle 中列出所有依赖包:

dependencies {
    ....
    implementation 'com.android.support:recyclerview-v7:28.0.0'
    implementation 'com.android.support:asynclayoutinflater:28.0.0'
    implementation 'com.android.support:animated-vector-drawable:28.0.0'
    implementation 'com.android.support:support-vector-drawable:28.0.0'
    implementation 'com.android.support:support-core-utils:28.0.0'
    implementation 'com.android.support:support-compat:28.0.0'
    implementation 'com.android.support:support-core-ui:28.0.0'
    implementation 'com.android.support:support-fragment:28.0.0'
    implementation 'com.android.support:support-annotations:28.0.0'
    implementation 'com.android.support:support-v4:28.0.0'
    implementation 'com.android.support:customtabs:28.0.0'
    implementation 'com.android.support:appcompat-v7:28.0.0'
    implementation 'com.android.support:cardview-v7:28.0.0'
    implementation 'com.android.support:design:28.0.0'
}

如果我至少省略上述行之一,我会收到 gradle 警告:All com.android.support libraries must use exactly same version specification (...). Found versions 28.0.0, 26.1.0。然后builder因为版本冲突而报错。

查看 gradle cache (~/.gradle/modules-2/files-2.1/com.android.support),我确实可以看到 28.0.0 和 26.1.0 版本。尝试从缓存中删除 v 26.1.0 并使用 com.android.support 实现行重建,除了第一个,注释掉。 Gradle 重新下载 v 26.1.0,我仍然得到错误!

有没有办法摆脱这种滋扰?

【问题讨论】:

  • 在此错误之前提到了哪个库依赖项?:(...). Found versions 28.0.0, 26.1.0 你是否通过运行./gradlew app:dependencies 进行检查
  • 检查你的项目 build.gradle 文件
  • 你在使用 buildToolsVersion '28.0.0' 如果你正在使用它,请在你的 gradle 中删除这一行,然后清理并再次构建 implementation 'com.android.support:support-v4:28.0.0'并替换为 support-v13:28.0.0

标签: android android-gradle-plugin build.gradle android-support-library


【解决方案1】:

感谢 Mohsen(如果可以的话,我会将他的评论标记为答案)我找到了罪魁祸首。

Google Play 服务广告使用 Android 支持库 26.1.0 版。

从 16.0.0 升级到 17.0.0 后,支持库的 v26.1.0 仍然被选中,正如你可以看到 gradlew app:dependencies 的摘录:

    +--- com.google.android.gms:play-services-ads:17.0.0
    |    +--- com.android.support:customtabs:26.1.0 -> 28.0.0
    |    |    +--- com.android.support:support-compat:28.0.0
    |    |    |    +--- com.android.support:support-annotations:28.0.0
    |    |    |    +--- com.android.support:collections:28.0.0
    |    |    |    |    \--- com.android.support:support-annotations:28.0.0
    |    |    |    +--- android.arch.lifecycle:runtime:1.1.1
    |    |    |    |    +--- android.arch.lifecycle:common:1.1.1
    |    |    |    |    |    \--- com.android.support:support-annotations:26.1.0 -> 28.0.0
    |    |    |    |    +--- android.arch.core:common:1.1.1
    |    |    |    |    |    \--- com.android.support:support-annotations:26.1.0 -> 28.0.0
    |    |    |    |    \--- com.android.support:support-annotations:26.1.0 -> 28.0.0
    |    |    |    \--- com.android.support:versionedparcelable:28.0.0
    |    |    |         +--- com.android.support:support-annotations:28.0.0
    |    |    |         \--- com.android.support:collections:28.0.0 (*)
    |    |    +--- com.android.support:support-annotations:28.0.0
    |    . . .
    |    +--- com.google.android.gms:play-services-ads-base:[17.0.0] -> 17.0.0
    |    +--- com.google.android.gms:play-services-ads-identifier:16.0.0
    |    |    \--- com.google.android.gms:play-services-basement:16.0.1
    |    |         \--- com.android.support:support-v4:26.1.0 -> 28.0.0
         . . .
    +--- com.google.android.ads.consent:consent-library:1.0.6
    |    +--- com.google.code.gson:gson:2.8.4
    |    \--- com.android.support:appcompat-v7:26.1.0 -> 28.0.0
         . . .

顺便说一句,据我了解,com.android.support:support-annotations:26.1.0 是从一些support-...:28.0.0 包中引用的。太棒了,不是吗?

现在我将列表减少到五行,它仍然可以正确构建:

implementation 'com.android.support:recyclerview-v7:28.0.0'
implementation 'com.android.support:customtabs:28.0.0'
implementation 'com.android.support:support-v4:28.0.0'
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support:support-annotations:28.0.0'

将不得不等待新的 Admob 广告发布,除非有人有更好的主意:)

【讨论】:

    猜你喜欢
    • 2019-01-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-03
    • 1970-01-01
    相关资源
    最近更新 更多