将Firebase库更新到16.0.0会引发Google Play服务依赖项问题

Qan*_*asi 5 android gradle firebase google-play-services

我的项目一直工作到一天,因为没有理由(我什么都没做),gradle开始给出这个奇怪的错误:

Program type already present: com.google.android.gms.internal.measurement.zzabo
Run Code Online (Sandbox Code Playgroud)

在发生此错误时,我的项目级别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
}
Run Code Online (Sandbox Code Playgroud)

这是我的应用程序级别的优点:

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'
Run Code Online (Sandbox Code Playgroud)

我搜索并在stackoverflow上找到了这个答案。表示该问题可能与Firebase依赖版本和google-services插件有关。因此,我将google-services插件版本更新为4.0.0firebase并将其更新为最新版本16.0.0。正如人们可能从gradle中期望的那样,它给出了另一个错误,该错误似乎与firebase版本16.0.0有关。

每当我将Firebase版本更改为16.0.0时,显然它也会尝试将Google Play服务依赖项也自动升级到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
Run Code Online (Sandbox Code Playgroud)

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

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

编辑:这个问题可以通过给出的解决方案来解决这个问题,但它仍然无法复制,因为在我的情况onesignal插件是只更新的克库版本,而不是火力版本。因此,面对此问题的任何人都不会搜索问题中使用的关键字。

小智 3

我相信您在相同的分辨率下遇到了与/sf/answers/3536128011/的海报相同的问题。

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