升级Google Play服务到11.0.0版本后出现错误

13

我遇到了一个奇怪的问题。在将Google Play服务库从版本10.2.6上传到版本11.0.0之后,当我尝试编译时,会出现以下错误:

Error:Execution failed for task ':app:processDebugGoogleServices'. 请通过更新google-services插件的版本(有关最新版本的信息可在https://bintray.com/android/android-tools/com.google.gms.google-services/上获得)或更新com.google.android.gms的版本至11.0.0来解决版本冲突。

我访问了错误中提到的链接,发现google-services插件的最新版本似乎是3.1.0,也就是我正在使用的版本,并且我已经将所有的play services库升级到了11.0.0版本。我该怎么做才能使用GMS 11.0.0版本编译我的代码呢?

这是我的build.gradle文件(模块范围):

apply plugin: 'com.android.application'
apply plugin: 'realm-android'

android {

    compileSdkVersion 25
    buildToolsVersion "25.0.2"
    defaultConfig {
        applicationId "com.example.app"
        minSdkVersion 15
        targetSdkVersion 25
        versionCode 23
        versionName "0.7.3.2"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        manifestPlaceholders = [onesignal_app_id               : "12345678-1234-1234-1234-123456789",
                            // Project number pulled from dashboard, local value is ignored.
                            onesignal_google_project_number: "REMOTE"]
        multiDexEnabled true
    }
    buildTypes {

        release {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

    productFlavors {
        prontopro {
            applicationId "com.example.app"
            buildConfigField "boolean", "TEST_ENVIRONMENT", "false"
        }

        prontoproTest {
            applicationId "com.example.app"
            buildConfigField "boolean", "TEST_ENVIRONMENT", "true"
        }
    }

    dataBinding {
        enabled = true
    }
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    compile 'com.android.support:multidex:1.0.1'
    compile 'com.android.support:appcompat-v7:25.3.1'
    compile 'com.android.support:design:25.3.1'
    compile 'com.google.android.gms:play-services-places:11.0.0'
    compile 'com.google.android.gms:play-services-location:11.0.0'
    compile 'org.parceler:parceler-api:1.1.6'
    annotationProcessor 'org.parceler:parceler:1.1.6'
    annotationProcessor 'com.android.databinding:compiler:2.2.2'
    compile 'com.viewpagerindicator:library:2.4.1'
    compile 'com.squareup.retrofit2:retrofit:2.1.0'
    compile 'com.squareup.retrofit2:converter-gson:2.1.0'
    compile 'com.squareup.okhttp3:logging-interceptor:3.4.2'
    compile 'com.google.code.gson:gson:2.7'
    compile 'com.github.bumptech.glide:glide:3.7.0'
    compile 'com.github.chrisbanes:PhotoView:1.2.6'
    compile 'de.hdodenhof:circleimageview:2.1.0'
    compile 'com.facebook.android:facebook-android-sdk:[4,5)'
    compile 'io.realm:android-adapters:2.0.0'
    compile 'com.google.firebase:firebase-crash:10.2.6'
    //reactive libraries
    compile 'io.reactivex:rxandroid:1.2.1'
    compile 'io.reactivex:rxjava:1.2.3'
    compile 'com.jakewharton.rxbinding:rxbinding:1.0.0'
    compile 'com.jakewharton.rxbinding:rxbinding-support-v4:1.0.0'
    compile 'com.jakewharton.rxbinding:rxbinding-appcompat-v7:1.0.0'
    compile 'com.jakewharton.rxbinding:rxbinding-design:1.0.0'
    compile 'com.jakewharton.rxbinding:rxbinding-recyclerview-v7:1.0.0'
    compile 'com.tbruyelle.rxpermissions:rxpermissions:0.8.2@aar'
    compile 'com.squareup.retrofit2:adapter-rxjava:2.1.0'
    compile 'com.github.pwittchen:reactivenetwork:0.8.0'
    compile 'com.hwangjr.rxbus:rxbus:1.0.5'
    compile 'com.f2prateek.rx.preferences:rx-preferences:1.0.2'
    //testing
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    testCompile 'junit:junit:4.12'
    testCompile 'org.mockito:mockito-core:2.6.3'
    //onesignal
    compile 'com.onesignal:OneSignal:3.4.4@aar'
    compile "com.mixpanel.android:mixpanel-android:5.1.0"
    compile 'com.google.android.gms:play-services-gcm:11.0.0'
}
apply plugin: 'com.google.gms.google-services'

最后,这是我的 build.gradle 文件(应用程序范围):

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.3.2'
        classpath 'io.realm:realm-gradle-plugin:3.1.4'
        classpath 'com.google.gms:google-services:3.1.0'
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        maven { url "http://dl.bintray.com/populov/maven" }
        maven { url "https://jitpack.io" }
        mavenCentral()
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}
6个回答

25

你需要删除这一行 apply plugin: 'com.google.gms.google-services'

因为 apply plugin: 'com.android.application' 已经有了相同的包名。

这就是冲突出现的地方。

更新:

请使用 Play 服务版本 11.0.1


糟糕,这个解决方案似乎又产生了一个奇怪的错误。现在如果我尝试构建,会出现以下错误:"error: cannot find symbol class ConnectionResult",该类的完整名称为com.google.android.gms.common.ConnectionResult。 - Mattia Ruggiero
1
我尝试使用这个类,使用你的build.gradle文件,对我来说它运行良好。请尝试清理项目,然后在SDK管理器中更新Play服务。 - dustblue
如果你像我一样同时使用了 FirebaseAuth,你会遇到这个错误:Default FirebaseApp is not initialized in this process com.yourpackage.yourpackage. Make sure to call FirebaseApp.initializeApp(Context) first. 如果你和我面临类似的情况,可以查看这里的 链接。也许那篇 Stack Overflow 的帖子可以帮助你解决问题,就像它帮助了我一样。 - Moses Aprico
为什么不使用 11.0.1..,而且你不需要删除那一行。 - Abhishek Singh
我已经应用了插件:'com.android.application',并且没有像compile 'com.google.android.gms:play-services:11.0.1'这样的行,但是什么都不起作用。 - Anuj
显示剩余3条评论

6
请使用 play 服务版本 12.0.0,在项目级别的 gradle 中使用 classpath 'com.google.gms:google-services:3.1.0'编辑:答案已更新至最新版本。

是的,看起来他们在11.0.1版本中修复了这个问题。迟到总比不到好 :) - Mattia Ruggiero

1
我的经验是以下内容:
项目 Gradle
dependencies {
    classpath 'com.android.tools.build:gradle:2.3.2'
    classpath 'com.google.gms:google-services:3.0.0'

应用 Gradle

compileSdkVersion 26
buildToolsVersion '26.0.0'
defaultConfig {
    minSdkVersion 16
    targetSdkVersion 26
    multiDexEnabled = true
}

依赖项

//    compile 'com.crittercism:crittercism-android-agent:+'
compile project(':paymentGatewayCommons')
compile project(':paypal')
compile project(':paytm')
compile project(':payu')
compile 'com.fasterxml.jackson.core:jackson-core:2.9.0.pr1'
compile 'com.fasterxml.jackson.core:jackson-annotations:2.9.0.pr1'
compile 'com.fasterxml.jackson.core:jackson-databind:2.9.0.pr1'
compile 'com.android.support:multidex:1.0.1'
compile 'com.google.android.gms:play-services:11.0.1'
compile 'com.google.android.gms:play-services-base:11.0.1'
//compile 'com.google.android.gms:play-services-appindexing:11.0.1'
//compile 'com.google.android.gms:play-services-contextmanager:11.0.1'
compile 'com.google.android.gms:play-services-places:11.0.1'
compile 'com.google.android.gms:play-services-nearby:11.0.1'
compile 'com.google.android.gms:play-services-maps:11.0.1'
compile 'com.google.android.gms:play-services-ads:11.0.1'
compile 'com.google.android.gms:play-services-auth:11.0.1'
compile 'com.google.android.gms:play-services-gcm:11.0.1'
compile 'com.google.android.gms:play-services-analytics:11.0.1'
compile 'com.google.android.gms:play-services-location:11.0.1'
compile 'com.google.maps.android:android-maps-utils:0.4.+'
compile 'com.google.zxing:core:3.2.0'
compile 'com.journeyapps:zxing-android-embedded:3.3.0@aar'
compile 'com.google.firebase:firebase-messaging:11.0.1'
compile 'com.google.firebase:firebase-core:11.0.1'
compile 'com.google.firebase:firebase-analytics:11.0.1'
compile 'com.flurry.android:analytics:6.4.2'
compile 'com.android.support.constraint:constraint-layout:+'
testCompile 'junit:junit:4.12'

是的,正如Abhishek Singh所说,Play Services库的11.0.1版本已经修复了这个问题。 - Mattia Ruggiero
不仅如此,还需要注释掉appindexing和contextmanager。只使用11.0.1对我来说是不起作用的。 - Siddharth
我在我的项目中没有使用那两个库,正如你可以在我上面发布的 build.gradle 文件中看到的。 - Mattia Ruggiero
你能贴出你使用的gradle设置吗?如果被接受的答案解决了我的问题,我很乐意删除我的回答。我的问题并没有被接受的答案解决,我认为这会帮助到寻找答案的其他人。我的目的是提高答案的质量。 - Siddharth
适用于我的Gradle设置与我在原始答案中发布的相同,唯一的区别是Play Services库的版本是11.0.1而不是11.0.0。dustblue发布的原始解决方案(您应该删除apply plugin: 'com.google.gms.google-services'这一行,因为apply plugin: 'com.android.application'已经有了相同的包)对我没有起作用,因为当与rxjava2库一起使用时,Play Services库的11.0.0版本存在奇怪的问题。最终,11.0.1版本运行得非常好,看来Google已经修复了这个问题 ;) - Mattia Ruggiero

1
你可能已经解决了这个问题,但是将Firebase插件更新到11.0.1也为我解决了这个问题。

@KNR 不要发布相同的答案。 - Abhishek Singh

1

在 Android Studio 进行重大更新后,请清理并重新构建您的项目。最好使用版本 10。


谢谢,但清理和重建没有起作用 :( Play服务的第10版可以工作,但我想升级到第11版。 - Mattia Ruggiero

0
尝试直接针对所需的服务进行定位,例如如果您想获取 SmsRetriver 编译。
compile 'com.google.android.gms:play-services-auth-api-phone:11.0.1'

而不是

compile 'com.google.android.gms:play-services:11.0.1'

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接