我正在尝试为Android O更新我的应用,并且这样做需要更新以支持库26.
我的compileSdkVersion是26,targetSdkVersion 26,buildToolsVersion 26.0.1,支持库版本是26.0.1,播放服务/ firebase消息是11.0.4。我使用Android Studio 3.0 b2和android gradle插件3.0.0-beta2。看来这个版本对支持库冲突更加敏感。
我必须手动排除支持依赖项以解决冲突,因为播放服务和firebase链接旧版本的支持库:
implementation("com.google.android.gms:play-services-auth:$playServicesVersion",{
exclude group: 'com.android.support'
})
implementation("com.google.android.gms:play-services-identity:$playServicesVersion",{
exclude group: 'com.android.support'
})
implementation("com.google.android.gms:play-services-base:$playServicesVersion",{
exclude group: 'com.android.support'
})
implementation("com.google.android.gms:play-services-analytics:$playServicesVersion",{
exclude group: 'com.android.support'
})
implementation("com.google.firebase:firebase-messaging:$playServicesVersion",{
exclude group: 'com.android.support'
})
implementation("com.google.firebase:firebase-analytics:$playServicesVersion",{
exclude group: 'com.android.support'
})
这修复了除了一个以外的所有依赖项冲突。
Google Play服务/ Firebase需要使用google-services gradle插件来解析生成的.json文件,并在应用中包含必要的密钥/秘密。我的build.grade有一个buildcript块,如下所示:
buildscript {
repositories {
maven { url "https://maven.google.com" }
jcenter()
}
dependencies {
classpath "com.google.gms:google-services:3.1.0"
}
}
在脚本结束时,我应用了插件。随着apply和classpath被注释掉,一切都正确编译。然而,似乎google-services 3.1.0增加了对支持库版本25.2.0的依赖,而我还没有能够弄清楚如何覆盖它。消息是:
- 出了什么问题:任务执行失败':app:preDevelopmentDebugBuild'。
Android依赖' com.android.support:support-v4'具有不同版本的编译(25.2.0)和运行时(26.0.1)类路径。您 应该通过DependencyResolution手动设置相同的版本
请注意,我甚至无法降级到支持库25.4.0,因为我得到了相同的错误(只需用25.4.0替换上面的消息中的26.0.1)。唯一有效的版本是25.2.0
运行包含类路径依赖关系的./gradlew app:dependencies
,给我这个:
compile - Compile dependencies for 'main' sources (deprecated: use 'implementation' instead).
\--- com.google.firebase:firebase-core:11.0.4
\--- com.google.firebase:firebase-analytics:[11.0.4] -> 11.0.4
+--- com.google.firebase:firebase-analytics-impl:[11.0.4] -> 11.0.4
| +--- com.google.android.gms:play-services-basement:[11.0.4] -> 11.0.4
| | \--- com.android.support:support-v4:25.2.0
| | +--- com.android.support:support-compat:25.2.0
| | | \--- com.android.support:support-annotations:25.2.0
| | +--- com.android.support:support-media-compat:25.2.0
| | | +--- com.android.support:support-annotations:25.2.0
| | | \--- com.android.support:support-compat:25.2.0 (*)
| | +--- com.android.support:support-core-utils:25.2.0
| | | +--- com.android.support:support-annotations:25.2.0
| | | \--- com.android.support:support-compat:25.2.0 (*)
| | +--- com.android.support:support-core-ui:25.2.0
| | | +--- com.android.support:support-annotations:25.2.0
| | | \--- com.android.support:support-compat:25.2.0 (*)
| | \--- com.android.support:support-fragment:25.2.0
| | +--- com.android.support:support-compat:25.2.0 (*)
| | +--- com.android.support:support-media-compat:25.2.0 (*)
| | +--- com.android.support:support-core-ui:25.2.0 (*)
| | \--- com.android.support:support-core-utils:25.2.0 (*)
| +--- com.google.firebase:firebase-iid:[11.0.4] -> 11.0.4
| | +--- com.google.android.gms:play-services-basement:[11.0.4] -> 11.0.4 (*)
| | \--- com.google.firebase:firebase-common:[11.0.4] -> 11.0.4
| | +--- com.google.android.gms:play-services-basement:[11.0.4] -> 11.0.4 (*)
| | \--- com.google.android.gms:play-services-tasks:[11.0.4] -> 11.0.4
| | \--- com.google.android.gms:play-services-basement:[11.0.4] -> 11.0.4 (*)
| +--- com.google.firebase:firebase-common:[11.0.4] -> 11.0.4 (*)
| \--- com.google.android.gms:play-services-tasks:[11.0.4] -> 11.0.4 (*)
+--- com.google.android.gms:play-services-basement:[11.0.4] -> 11.0.4 (*)
\--- com.google.firebase:firebase-common:[11.0.4] -> 11.0.4 (*)
答案 0 :(得分:5)
configurations.all {
resolutionStrategy.eachDependency { DependencyResolveDetails details ->
def requested = details.requested
if (requested.group == 'com.android.support') {
if (!requested.name.startsWith("multidex")) {
details.useVersion '26.0.1'
}
}
}
}
像这样,您的支持库应该使用相同的版本进行编译。只需将模块级Gradle构建脚本中的代码段添加到依赖项中。
答案 1 :(得分:0)
看来这个问题实际上与子模块中包含的依赖关系有关。支持库通过一个共同的子模块包含在内,例如:
implementation project(':common')
我也尝试过:
implementation(project(':common'),{transitive = true})
但这没有任何区别。
唯一有效的方法是直接在我的顶级build.gradle中包含支持库