android - 如何用 gradle 解决所有 google play-services 依赖?

标签 android firebase gradle android-gradle-plugin google-play-services

情况

今天,我的gradle 对我大吼大叫,不编译项目。它无法解析 firebase-iidfirebase-commonplay-services-analytics-implplay-services-auth- api-phoneplay-services-auth-base。周末过后真是一团糟。

所以我检查了不同API的版本,并升级了那些需要升级的,发现谷歌已经为firebase-core添加了强制依赖,添加它,然后升级了我的google-services 插件,甚至添加了 play-services-base 依赖项。我还将 firebase-messaging 升级到 17.0.0 版,将 crashlytics 升级到 2.9.3 版。

但是,构建仍然无法编译,并显示以下错误消息:

The library com.google.android.gms:play-services-measurement-base is being requested by various other libraries at [[15.0.2,15.0.2], [15.0.4,15.0.4]], but resolves to 15.0.4. Disable the plugin and check your dependencies tree using ./gradlew :app:dependencies.

Gradle 文件

这是我尝试修复后的 Gradle 文件(仅显示依赖项部分):

apply plugin: 'com.android.application'

...
dependencies {
    implementation project(':library')
    implementation project(':otherlibrary')
    implementation 'com.android.volley:volley:1.1.0'
    implementation('org.apache.httpcomponents:httpmime:4.3.6') {
        exclude module: 'httpclient'
    }
    implementation 'org.apache.httpcomponents:httpclient-android:4.3.5'
    implementation 'com.google.android.gms:play-services-base:15.0.1'
    implementation 'com.google.android.gms:play-services-analytics:15.0.2'
    implementation 'com.google.android.gms:play-services-location:15.0.1'
    implementation('com.google.android.gms:play-services-ads:15.0.1') {
        exclude group: 'com.android.support', module: 'customtabs'
    }
    implementation 'com.google.android.gms:play-services-identity:15.0.1'
    implementation 'com.google.android.gms:play-services-auth:15.0.1'
    implementation 'com.google.android.gms:play-services-drive:15.0.1'
    implementation 'com.google.firebase:firebase-core:16.0.0'
    implementation 'com.google.firebase:firebase-messaging:17.0.0'

    implementation 'com.android.support:multidex:1.0.3'
    implementation 'com.readystatesoftware.sqliteasset:sqliteassethelper:2.0.1'
    implementation 'com.squareup.picasso:picasso:2.5.2'
    implementation 'com.nineoldandroids:library:2.4.0'
    implementation 'com.daimajia.slider:library:1.1.5@aar'
    implementation 'com.android.support.constraint:constraint-layout:1.1.0'
    implementation 'com.android.support:appcompat-v7:27.1.1'
    implementation 'com.android.support:mediarouter-v7:27.1.1'
    implementation 'com.android.support:support-v4:27.1.1'
    implementation 'com.android.support:design:27.1.1'
    implementation 'com.android.support:exifinterface:27.1.1'
    implementation 'com.android.support:support-v13:27.1.1'
    // https://mvnrepository.com/artifact/com.darwinsys/hirondelle-date4j
    implementation group: 'com.darwinsys', name: 'hirondelle-date4j', version: '1.5.1'
    // For RxAndroid and RxJava
    implementation 'io.reactivex.rxjava2:rxandroid:2.0.2'
// Because RxAndroid releases are few and far between, it is recommended you also
// explicitly depend on RxJava's latest version for bug fixes and new features.
// (see https://github.com/ReactiveX/RxJava/releases for latest 2.x.x version)
    implementation 'io.reactivex.rxjava2:rxjava:2.1.12'

    // Crashlytics
    implementation 'com.crashlytics.sdk.android:crashlytics:2.9.3'

    // CSV with outputstream writer
    implementation 'com.opencsv:opencsv:4.1'

    // Gson
    implementation 'com.google.code.gson:gson:2.8.5'

    debugImplementation 'com.android.support.test:runner:1.0.2'

    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test:rules:1.0.2'
    androidTestImplementation 'org.hamcrest:hamcrest-library:1.3'
    androidTestImplementation 'junit:junit:4.12'
}

apply plugin: 'com.google.gms.google-services'

我的项目范围内的 gradle 包含这些行:

...
repositories {
    maven {
       url 'https://maven.google.com/'
       name 'Google'
    }
    ...
}
dependencies {
    ...
    classpath 'com.google.gms:google-services:4.0.1'
}
...

官方解决方案无效

我已经尝试根据 official firebase documentation 修复多个库的版本号,这或多或少与 this question 相同.
正如您在官方文档链接中看到的那样,截至 2018 年 5 月 2 日,他们提供了一种解决此类问题的方法,但有问题的版本号不一样,我已经尝试了给定的修复(与现在有些降级),但无济于事。

Official documentation: If your app has a dependency on com.google.firebase:firebase-core:15.0.0 as well as any of the following libraries:

com.google.android.gms:play-services-analytics
com.google.android.gms:play-services-appinvite
com.google.android.gms:play-services-tagmanager
com.google.firebase:firebase-analytics
com.google.firebase:firebase-crash
com.google.firebase:firebase-dynamic-links
com.google.firebase:firebase-messaging

You will need to update the version of the latter dependency to 15.0.2. This addresses the issue where version 3.3.0 of the Google Services Gradle plugin reports: The library com.google.android.gms:play-services-measurement-base is being requested by various other libraries at [[15.0.0,15.0.0], [15.0.2,15.0.2]], but resolves to 15.0.2...

那么如何解决这些版本冲突,以便我的构建再次正确编译?

最佳答案

所以在这个问题上迷茫了一天之后,我发现最新版本的 play-services-analytics 不是他们在 their website 中发布的版本.它是 16.0.0 而不是 15.0.2

Android Studio 将此作为警告告诉同事,但我的同事对此并不关心。所以在这里,改变一切的行:

implementation 'com.google.android.gms:play-services-analytics:16.0.0'

关于android - 如何用 gradle 解决所有 google play-services 依赖?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50565053/

相关文章:

android - 我在运行应用程序时收到 SQLCipher 错误

android - 此Gradle系列对Android的功能有什么作用

git - 警告 : buildx: failed to read current commit information with git rev-parse --is-inside-work-tree

java - Exoplayer 2.7.0 , 2.3.1 版本冲突

android - "Downloads"应用程序中显示的文件的文件类型注册失败

android - 在android中混淆我的源代码

javascript - 将多个选定选项传递给 Angular 中的 Firebase 查询(AngularFire2)

android - 传入参数时 Kotlin 类型不匹配

java - 为什么即使元素未插入到 Firestore 文档中的数组中,也会调用 successListener?

android - 如何在 FirebaseAnalytics for Unity3D 中设置 userId?