【问题标题】:How to resolve all google play-services dependencies with gradle?如何使用 gradle 解决所有 google play-services 依赖项?
【发布时间】:2018-11-06 23:16:18
【问题描述】:

情况

今天,我的 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 版。

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

库 com.google.android.gms:play-services-measurement-base 正在 [[15.0.2,15.0.2], [15.0.4,15.0.4]] 的各种其他库请求,但解析为 15.0.4。禁用插件并使用 ./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 日,他们提供了一种解决此类问题的方法,但有问题的版本数量并不相同,我已经尝试了给定的修复(使用现在有些降级),无济于事。

官方文档: 如果您的应用依赖于 com.google.firebase:firebase-core:15.0.0 以及以下任何库:

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

您需要将后一个依赖项的版本更新为 15.0.2。这解决了 3.3.0 版 Google Services Gradle 插件报告的问题:库 com.google.android.gms:play-services-measurement-base 正在 [[15.0.0,15.0.0] 的各种其他图书馆要求, [15.0.2,15.0.2]],但解析为 15.0.2...

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

【问题讨论】:

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


    【解决方案1】:

    我将它添加到我的 build.gradle(应用程序版本)中并且它有效:

    googleServices { disableVersionCheck = true }
    

    (请记住,这只是为了禁用版本检查,它实际上并没有修复任何问题)

    【讨论】:

    • 请问您是在哪里添加的?
    • @DrissBounouar 我将它添加到应用程序级别(不是项目级别)的 build.gradle 底部
    • 其实只是治标不治本。稍后您的应用可能会遇到一些问题,然后您必须更正版本
    • @DevanshMaurya 显然因为它只是禁用了检查,但它现在可以完成这项工作。我不知道如何设置所有正确的版本,因为它们捆绑在其他依赖项中。
    【解决方案2】:

    不幸的是,谷歌播放服务已停止 这个寡妇味精是生成的&从不运行任何谷歌服务执行

    【讨论】:

      【解决方案3】:

      我尝试恢复到旧版本,它似乎可以工作,我发现gradle-wrapper.properties 使用的是旧版本 (4.5) 而不是我在新项目中使用的 4.6。更改此设置以及从 alpha15 恢复为 classpath 'com.android.tools.build:gradle:3.2.0-alpha08' 似乎可以解决问题。我认为如果你愿意,你可以使用 alpha 15,但要确保你可以使用classpath 'com.android.tools.build:gradle:3.1.2'。 除了所有这些更改之外,firebase-coregoogle-gms-services 应设置为版本 16.0.0。

      【讨论】:

      • 我将我的gradle-wrapper.properties 升级到 4.6-all 或 4.7-all,并且我已经拥有了 classpath 'com.android.tools.build:gradle:3.1.2',但错误仍然存​​在......我目前正在尝试排除 @ 987654328@ 从所有依赖项中直接导入。目前,不工作。
      【解决方案4】:

      所以在这个问题上迷失了一天之后,我发现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 Studio 会抱怨本地缓存中有(可能)更新的版本...
      • 您可以随时查看谷歌存储库以获取最新版本dl.google.com/dl/android/maven2/index.html
      猜你喜欢
      • 1970-01-01
      • 2020-09-15
      • 1970-01-01
      • 1970-01-01
      • 2018-06-27
      • 1970-01-01
      • 2019-08-19
      • 1970-01-01
      • 2019-03-27
      相关资源
      最近更新 更多