Android studio play-services-ads:12.0.1与appcompat-v7冲突:27.1.0

时间:2018-04-03 06:51:34

标签: android-studio gradle google-play-services android-support-library

我正在使用谷歌ADS sdk构建一个应用程序,它工作正常,直到今天我收到更新Android工作室的通知,同时我还提示将Gradle更新到4.4并将所有支持库版本更新到27.1.0。

implementation 'com.android.support:appcompat-v7:27.1.0'
implementation 'com.google.android.gms:play-services-ads:12.0.1'

然后我收到Gradle错误,说 Android依赖'com.android.support:support-v4'对于编译(26.1.0)和运行时(27.1.0)类路径有不同的版本。您应该通过DependencyResolution

手动设置相同的版本

我搜索了我的代码,并没有一个词可以匹配“26.1.0”。我也试图删除所有的构建/ gradle缓存,但仍然无法摆脱这个问题。所以我使用 gradlew.bat -q依赖来发现ADS库似乎有错误的依赖。

这两行非常可疑:

+--- com.android.support:support-v4:26.1.0
+--- com.android.support:support-media-compat:26.1.0

与其他依赖设置相比

+--- project :MyAdsProject
+--- com.android.support:appcompat-v7:27.1.0
|    +--- com.android.support:support-annotations:27.1.0
|    +--- com.android.support:support-core-utils:27.1.0
|    |    +--- com.android.support:support-annotations:27.1.0
|    |    \--- com.android.support:support-compat:27.1.0
|    |         +--- com.android.support:support-annotations:27.1.0
|    |         \--- android.arch.lifecycle:runtime:1.1.0
|    |              +--- android.arch.lifecycle:common:1.1.0
|    |              \--- android.arch.core:common:1.1.0
|    +--- com.android.support:support-fragment:27.1.0
|    |    +--- com.android.support:support-compat:27.1.0 (*)
|    |    +--- com.android.support:support-core-ui:27.1.0
|    |    |    +--- com.android.support:support-annotations:27.1.0
|    |    |    +--- com.android.support:support-compat:27.1.0 (*)
|    |    |    \--- com.android.support:support-core-utils:27.1.0 (*)
|    |    +--- com.android.support:support-core-utils:27.1.0 (*)
|    |    +--- com.android.support:support-annotations:27.1.0
|    |    +--- android.arch.lifecycle:livedata-core:1.1.0
|    |    |    +--- android.arch.lifecycle:common:1.1.0
|    |    |    +--- android.arch.core:common:1.1.0
|    |    |    \--- android.arch.core:runtime:1.1.0
|    |    |         \--- android.arch.core:common:1.1.0
|    |    \--- android.arch.lifecycle:viewmodel:1.1.0
|    +--- com.android.support:support-vector-drawable:27.1.0
|    |    +--- com.android.support:support-annotations:27.1.0
|    |    \--- com.android.support:support-compat:27.1.0 (*)
|    \--- com.android.support:animated-vector-drawable:27.1.0
|         +--- com.android.support:support-vector-drawable:27.1.0 (*)
|         \--- com.android.support:support-core-ui:27.1.0 (*)
\--- com.google.android.gms:play-services-ads:12.0.1
     +--- com.google.android.gms:play-services-ads-lite:12.0.1
     |    +--- com.google.android.gms:play-services-basement:12.0.1
     |    |    +--- com.android.support:support-v4:26.1.0
     |    |    |    +--- com.android.support:support-compat:26.1.0 -> 27.1.0 (*)
     |    |    |    +--- com.android.support:support-media-compat:26.1.0
     |    |    |    |    +--- com.android.support:support-annotations:26.1.0 -> 27.1.0
     |    |    |    |    \--- com.android.support:support-compat:26.1.0 -> 27.1.0 (*)
     |    |    |    +--- com.android.support:support-core-utils:26.1.0 -> 27.1.0 (*)
     |    |    |    +--- com.android.support:support-core-ui:26.1.0 -> 27.1.0 (*)
     |    |    |    \--- com.android.support:support-fragment:26.1.0 -> 27.1.0 (*)
     |    |    \--- com.google.android.gms:play-services-basement-license:12.0.1
     |    \--- com.google.android.gms:play-services-ads-lite-license:12.0.1
     +--- com.google.android.gms:play-services-basement:12.0.1 (*)
     +--- com.google.android.gms:play-services-gass:12.0.1
     |    +--- com.google.android.gms:play-services-basement:12.0.1 (*)
     |    \--- com.google.android.gms:play-services-gass-license:12.0.1
     \--- com.google.android.gms:play-services-ads-license:12.0.1

有人如何摆脱这个? ADS 12.0.1目前已经是最新版本。

2 个答案:

答案 0 :(得分:5)

在您的应用级build.gradle

android {
    configurations.all {
        resolutionStrategy.force 'com.android.support:support-v4:27.1.1'
    }
}

这将告诉您的gradle配置在其导入的任何地方强行挑选并应用support-v4:27.1.1

希望这有帮助!

答案 1 :(得分:0)

我可以通过将其添加到我的行为中来解决此问题

implementation 'com.android.support:support-v4:28.0.0'

OR

将此代码添加到您的应用程序gradle中

android {
    configurations.all {
        resolutionStrategy.force 'com.android.support:support-v4:28.0.0'
    }
}