错误:使用productFlavors修复版本冲突(google-services插件)

8
我知道版本冲突的问题,但即使从Google获得了新版本,问题仍然存在。
错误信息:执行任务失败':app:processCurrentDebugGoogleServices'。请通过更新google-services插件版本(关于最新版本的信息可在https://bintray.com/android/android-tools/com.google.gms.google-services/上找到),或将com.google.android.gms的版本更新为11.4.0来解决版本冲突。
我的build.gradle(Module: app):
apply plugin: 'com.android.application'

android {
    compileSdkVersion 26
    buildToolsVersion "26.0.1"
    defaultConfig {
        applicationId "com.x.x"
        minSdkVersion 9
        targetSdkVersion 26
        versionCode 10
        versionName "1.1"
        vectorDrawables.useSupportLibrary = true
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

    productFlavors {
        legacy {
            minSdkVersion 9

        }
        current {
            minSdkVersion 14
        }
    }

}

    dependencies {
       compile fileTree(dir: 'libs', include: ['*.jar'])
       androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
        })
       testCompile 'junit:junit:4.12'

    legacyCompile 'com.google.firebase:firebase-ads:10.0.1'
    legacyCompile 'com.google.firebase:firebase-core:10.0.1'

    currentCompile 'com.google.firebase:firebase-ads:11.4.0'
    currentCompile 'com.google.firebase:firebase-core:11.4.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.3'
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
        classpath 'com.google.gms:google-services:3.1.1'
    }
}

allprojects {
    repositories {
        jcenter()
        maven { url 'https://maven.google.com' }
    }
}

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


现在需要做哪些更改?

谢谢。


1
请问您能否展示您的根级别 build.gradle 文件呢?它应该包含类似于以下内容的代码块:dependencies { classpath 'com.android.tools.build:gradle:3.0.0-beta6' classpath 'com.google.gms:google-services:3.0.0' } - Peter
好的,我修改了我的问题,谢谢。 - iLyas
3个回答

11

真正的解决方案只是移动

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

在(app)build.gradle 脚本底部添加内容,并重新构建项目。 百分之百有效。


你能详细说明一下吗?这确实解决了我的构建问题,但我不明白为什么... - fgysin
这是一个非常好的问题,没有人能够回答。我认为这可能与引用尚未创建的依赖项有关。就像在声明变量之前调用它一样。 - Darko Bacic

5
冲突是由插件的新版本和Play Services/Firebase依赖之间产生的。
对于不同的产品口味,您不能应用相同插件的不同版本,因此在尝试在不同口味中使用不同的Play Services依赖项时,会遇到此冲突。
您可以:
  • 在应用的新版本中放弃对API级别低于14的用户1%的支持
  • 保持旧版的Play Services/Firebase版本,仍然支持14

1
您应该删除这行代码:

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

因为应用插件:'com.android.application'已经有相同的包,这就是冲突产生的原因。

@GowthamanM 你从哪里看到这些信息的?请在此处查看官方指南。https://developers.google.com/android/guides/google-services-plugin - Gabriele Mariotti
请检查是否同时添加了 apply plugin: 'com.android.application'apply plugin: 'com.google.gms.google-services',以确定是否会出现冲突。 - Gowthaman M
@Gowthaman M 这不是最好的答案,有些地方有问题!无论如何,谢谢。 - iLyas

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