版本冲突更新到播放服务9.4.0 Android studio 2.2

tba*_*bag 51 android gradle google-play-services android-studio

我收到一个错误说

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

我试着查看https://bintray.com/android/android-tools/com.google.gms.google-services/和com.google.gms:google-services:3.0.0似乎是最新的.这是我的项目

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

这就是我的应用程序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'
    }
Run Code Online (Sandbox Code Playgroud)

如果我将播放服务更改为9.0.0,一切都编译好了.我在这里错过了什么?

ian*_*ake 149

您需要将该apply plugin: 'com.google.gms.google-services'行放在dependencies块下方- 这允许插件确定您正在使用的Play服务版本.

  • @LongDao - 该文件与计算机程序的共同点多于配置文件 - 它按顺序读取和执行.通过在`dependencies`块之前放置`apply plugin`行,插件会在知道您实际使用的Google Play服务版本之前执行并配置您的构建 - 它实际上无法"预读" (9认同)
  • 是的,它的工作原理.只是很好奇,我把apply plugin .....放在块的顶部,看起来它不起作用.为什么它必须低于块? (5认同)
  • 我收到错误:插件时找不到ID"com.google.gms.google-services".知道怎么解决吗? (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'
Run Code Online (Sandbox Code Playgroud)

所有必须具有相同的9.6.1版本