将 firebase 库更新到 16.0.0 会引发 google 播放服务依赖性问题

Updating firebase library to 16.0.0 raises google play services dependency issue

直到有一天我的项目都运行良好,因为没有任何原因(我没有改变任何东西),gradle开始出现这个奇怪的错误:

Program type already present: com.google.android.gms.internal.measurement.zzabo

出现此错误时,我的项目级别 gradle 是这样的:

buildscript {
    repositories {
        jcenter()
        maven {
            url 'https://maven.google.com'
            // Alternative URL is 'https://dl.google.com/dl/android/maven2/'
        }
        maven { url 'https://plugins.gradle.org/m2/'}
        maven { url 'https://maven.fabric.io/public' }
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.1.2'
        classpath 'com.google.gms:google-services:4.0.0'
        classpath 'io.fabric.tools:gradle:1.25.3'
        classpath 'gradle.plugin.com.onesignal:onesignal-gradle-plugin:0.8.1'
    }
}

allprojects {
    repositories {
        jcenter()
        maven {
            url 'https://dl.bintray.com/sayyam/maven'
        }
        maven {
            url "https://jitpack.io"
        }
        maven {
            url 'https://maven.google.com'
        }
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

这是我的应用级别 gradle:

apply plugin: 'com.android.application'
apply plugin: 'com.onesignal.androidsdk.onesignal-gradle-plugin'
apply plugin: 'io.fabric'

android {
    compileSdkVersion 27
    buildToolsVersion "27.0.3"

    dexOptions {
        javaMaxHeapSize "4g"
    }
    packagingOptions {
        exclude 'META-INF/rxjava.properties'
    }
    defaultConfig {
        applicationId "com.example"
        deviceCheck
        minSdkVersion 17
        targetSdkVersion 27
        versionCode 8
        versionName "1.0"
        vectorDrawables.useSupportLibrary = true
        multiDexEnabled true
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
}

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation 'com.google.firebase:firebase-invites:15.0.1'
    implementation 'com.google.firebase:firebase-core:15.0.2'
    implementation 'com.crashlytics.sdk.android:crashlytics:2.9.2'
    implementation 'com.google.android.gms:play-services-maps:15.0.1'
    implementation 'com.google.android.gms:play-services-location:15.0.1'
    implementation 'com.google.android.gms:play-services-places:15.0.1'
    implementation 'com.google.maps.android:android-maps-utils:0.5'
    implementation 'com.android.support:support-v13:27.1.1'
    implementation 'com.android.support:support-v4:27.1.1'
    implementation 'com.android.support:appcompat-v7:27.1.1'
    .....other dependencies.....
    testImplementation 'junit:junit:4.12'
}
apply plugin: 'com.google.gms.google-services'

我在 Whosebug 上搜索并找到了 答案。这表示此问题可能与 firebase 依赖版本和 google-services 插件有关。所以我将 google-services 插件版本更新为 4.0.0 并将 firebase 更新为最新版本 16.0.0。正如 gradle 所预料的那样,它给出了另一个似乎与 firebase 版本 16.0.0 有关的错误。

每当我将 firebase 版本更改为 16.0.0 时,显然它也会尝试自动将 google 播放服务依赖项升级到 16.0.0。哪个根本不存在!它引发以下 gradle 错误:

Failed to resolve: com.google.android.gms:play-services-maps:16.0.0
Failed to resolve: com.google.android.gms:play-services-location:16.0.0 
Failed to resolve: com.google.android.gms:play-services-places:16.0.0   
Failed to resolve: com.google.android.gms:play-services-gcm:16.0.0  
Failed to resolve: com.google.android.gms:play-services-base:16.0.0 
Failed to resolve: com.google.android.gms:play-services-basement:16.0.0 
Failed to resolve: com.google.android.gms:play-services-measurement-base:16.0.0 
Failed to resolve: com.google.android.gms:play-services-tasks:16.0.0    
Failed to resolve: com.google.android.gms:play-services-stats:16.0.0
Failed to resolve: com.google.android.gms:play-services-ads-identifier:16.0.0

我尝试使用 resolutionStrategy 强制 gms 库的版本,但无济于事。我应该怎么办?我做错了什么?

注意:我没有明确更改播放服务库版本,gradle 似乎是因为 firebase 才这样做。

编辑: 这个问题可以通过 question, but still its not duplicate because in my case onesignal plugin was updating only gms libraries version and not firebase version. So anybody facing this problem won't search for keywords used in 问题中给出的解决方案来解决。

我相信您 运行 遇到了与 的海报相同的问题,分辨率相同。

基本上,com.onesignal.androidsdk.onesignal-gradle-plugin 插件会强制提升您对不存在的东西的依赖性。