无法使用带有各种风格的Gradle和com.google.gms.google-services插件

时间:2017-03-09 11:01:56

标签: android gradle google-play-services android-productflavors android-min-sdk

当我尝试使用基于minSdk的风格编译我的应用程序时,我收到错误:

  

错误:任务执行失败   ':应用程序:processCurrentDebugGoogleServices'。

     
    

请通过更新google-services插件的版本来修复版本冲突(有关最新版本的信息是     可在     https://bintray.com/android/android-tools/com.google.gms.google-services/)     或将com.google.android.gms的版本更新为10.2.0。

  

我从Android Developers Blog粘贴了示例,但它无效。

项目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.0'
        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
    }
}

allprojects {
    repositories {
        jcenter()
    }
}

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

app gradle:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 25
    buildToolsVersion '25.0.2'
    defaultConfig {
        applicationId 'pl.net.szafraniec.testApp'
        minSdkVersion 10
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    productFlavors {
        legacy {
            minSdkVersion 9
            versionCode 901  // Min API level 9, v01
        }
        current {
            minSdkVersion 14
            versionCode 1401  // Min API level 14, v01
        }
    }
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    legacyCompile 'com.google.android.gms:play-services:10.0.0'
    currentCompile 'com.google.android.gms:play-services:10.2.0'
    compile 'com.android.support:appcompat-v7:25.2.0'
    compile 'com.android.support:design:25.2.0'
    testCompile 'junit:junit:4.12'
    compile 'com.f2prateek.ln:ln:1.1.1'
}
apply plugin: 'com.google.gms.google-services'

1 个答案:

答案 0 :(得分:0)

此问题的一个workaround是将apply plugin: 'com.google.gms.google-services'行放在您的依赖项块下面,这样可以让插件确定您正在使用的Play服务版本。既然您已经这样做了,请尝试下载Google Support Repository。您可以在Tools - >中找到它。 Android - > SDK Manager - > SDK Tools

您还可以查看此相关SO帖子中的答案:Google Play Services GCM 9.2.0 asks to "update" back to 9.0.0