我的项目中使用的第三方库之一需要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缓存(~/.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,仍然出现错误!
有办法消除这种麻烦吗?
答案 0 :(得分:2)
感谢莫森(我会尽可能将他的评论标记为答案),我找到了罪魁祸首。
Android支持库的26.1.0版供Google Play服务广告使用。
从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 Ads发布:)