升级到play-services 9.4.0时出现版本冲突,Android studio 2.2

51

我收到一个错误信息,内容为

 Error:Execution failed for task ':app:processDebugGoogleServices'.
    > Please fix the version conflict either by updating the version of the google-services plugin (information about the latest version is available at https://bintray.com/android/android-tools/com.google.gms.google-services/) or updating the version of com.google.android.gms to 9.0.0.

我尝试查看https://bintray.com/android/android-tools/com.google.gms.google-services/,发现com.google.gms:google-services:3.0.0似乎是最新的版本。这是我的项目gradle文件:

dependencies {
            classpath 'com.android.tools.build:gradle:2.1.2'
            classpath 'com.google.gms:google-services:3.0.0'
            // NOTE: Do not place your application dependencies here; they belong
            // in the individual module build.gradle files
        }

这是我的应用 gradle 的样子

buildscript {
        repositories {
            maven { url 'https://maven.fabric.io/public' }
        }

        dependencies {
            classpath 'io.fabric.tools:gradle:1.+'
        }
    }
    apply plugin: 'com.android.application'
    apply plugin: 'io.fabric'
    apply plugin: 'com.google.gms.google-services'

    repositories {
        maven { url 'https://maven.fabric.io/public' }
    }


    android {
        compileSdkVersion 24
        buildToolsVersion "24.0.1"
        useLibrary 'org.apache.http.legacy'

        defaultConfig {
            applicationId "com.myapp.preburn"
            minSdkVersion 10
            targetSdkVersion 24
            versionCode 14
            versionName "2.0.1"
            renderscriptTargetApi 22
            renderscriptSupportModeEnabled true
        }
        buildTypes {
            release {
                lintOptions {
                    disable 'MissingTranslation'
                }
                minifyEnabled false
                proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            }
        }
    }

    android {
        packagingOptions {
            exclude 'META-INF/DEPENDENCIES'
            exclude 'META-INF/NOTICE'
            exclude 'META-INF/LICENSE'
        }
    }

    repositories {
        mavenCentral()
        jcenter()
    }

    dependencies {
        compile fileTree(dir: 'libs', include: ['*.jar'])
        compile fileTree(dir: 'libs', include: 'Parse-*.jar')
        compile 'com.parse.bolts:bolts-android:1.2.0'
        compile 'com.android.support:appcompat-v7:24.1.1'
        compile 'com.mcxiaoke.volley:library:1.0.9'
        compile 'com.google.android.gms:play-services-gcm:9.4.0'
        compile 'com.google.android.gms:play-services-location:9.4.0'
        compile 'com.google.android.gms:play-services-maps:9.4.0'
        compile 'com.google.android.gms:play-services-ads:9.4.0'
        compile 'com.google.android.gms:play-services-plus:9.4.0'
        compile 'com.google.android.gms:play-services-analytics:9.4.0'
        compile 'me.leolin:ShortcutBadger:1.1.3@aar'
        compile 'com.squareup.picasso:picasso:2.5.2'
        compile files('libs/jsoup-1.7.3.jar')
        compile('com.crashlytics.sdk.android:crashlytics:2.5.5@aar') {
            transitive = true;
        }
        compile files('libs/InMobi-5.2.2.jar')
        compile files('libs/libadapterinmobi.jar')
        compile files('libs/StartAppAdMobMediation-1.0.1.jar')
        compile files('libs/StartAppInApp-3.3.1.jar')
        compile 'org.adw.library:discrete-seekbar:1.0.1'
        compile 'com.pnikosis:materialish-progress:1.0'
    }

如果我将Play服务更改为9.0.0,一切都能编译成功。我在这里错过了什么?

10个回答

149

dependencies块下面添加apply plugin: 'com.google.gms.google-services',这样插件就可以确定您使用的Play服务版本。


5
是的,它有效。只是好奇,我把“apply plugin.....”放在块的顶部,似乎它不起作用。为什么它必须在块下面? - Long Dao
9
@LongDao - 这个文件更像是一个计算机程序而不是配置文件 - 它是按顺序读取和执行的。通过在 dependencies 块之前放置 apply plugin 行,插件可以在知道实际使用的 Google Play 服务版本之前执行和配置您的构建 - 它实际上无法“预读”。 - ianhanniballake
哦,我明白了,所以代码的顺序在这里确实很重要。感谢您的解释。 :) - Long Dao
3
我发现一个错误:找不到ID为'com.google.gms.google-services'的插件。有什么办法解决吗? - Anirudh
1
@Anirudh - 这听起来完全是另一个问题。 - ianhanniballake
显示剩余3条评论

62
如果您有Firebase依赖项,请将它们的版本更新为与Google服务的版本相匹配: 例如:
 //Firebase Crashreports
 compile 'com.google.firebase:firebase-crash:9.6.1'
//Firebase Analytics
compile 'com.google.firebase:firebase-core:9.6.1'
compile 'com.google.android.gms:play-services-analytics:9.6.1'
compile 'com.google.android.gms:play-services-gcm:9.6.1'

所有人都必须使用相同的9.6.1版本。


这对我有效,即使在文档中Google Play服务使用9.8.0,你必须与Firebase依赖项匹配版本。 - aldok
1
感谢您的回答。我注意到所有play-services和firebase-crash的版本应该匹配(在我的情况下是9.4.0)。 - onexf
大家好!每次我从9.8.0移动到9.6.1后启动它,它就会回到9.8.0...有什么想法吗?这将非常酷!:D - luiswill

3
只需在依赖项后面写入此内容。
apply plugin: 'com.google.gms.google-services'

1
我遇到了同样的问题。
我的解决方案是不在代码中添加任何内容,而是下载Google支持库 - 你可以在工具 -> Android -> SDK管理器 -> SDK工具中找到它。

1
只需在依赖项下方应用以下google-services即可。这对我很有效。

1

我遇到了类似的问题。当我将插件添加到顶部时,它对我没有起作用。因此,将插件添加到 gradle 的底部。这解决了我的版本冲突问题。

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

并将以下行添加为其依赖项。
 compile 'com.google.firebase:firebase-core:9.2.0' 
 compile 'com.google.firebase:firebase-messaging:9.2.0'
compile 'com.google.android.gms:play-services-location:9.2.0'
compile 'com.google.android.gms:play-services-places:9.2.0'

1
你有这行代码吗?
apply plugin: 'com.google.gms.google-services' 

在你的build.gradle文件末尾加入这一行?
当"apply plugin"放在顶部时,大多数情况下会出现这个错误。

0

我安装了Google Repository:

Android > SDK Manager。 更新Android Studio SDK Manager:点击SDK工具,展开支持库,选择Google Repository,然后点击确定。


-1
这个问题实际上花费了我很多时间,但是我通过应用插件com.google.gms.google-services解决了它。
重要提示:确保不要将其放在gradle文件的顶部,而是在依赖块后使用它。

-1

只需前往 /platforms/android/cordova-plugin-fcm/*-FCMPlugin.gradle

查找

classpath 'com.google.gms:google-services:+'

替换它为

classpath 'com.google.gms:google-services:3.0.0'

重新构建。


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