使用com.google.android.gms构建错误build.gradle:play-services-maps:9.4.0

时间:2016-09-15 07:33:57

标签: android android-gradle build.gradle

在我的应用程序中,我有这些依赖项:

apply plugin: 'com.android.application'
android {
    compileSdkVersion 23
    buildToolsVersion "23.0.2"

    defaultConfig {
        applicationId "com.package_app.name"
        minSdkVersion 15
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}
dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:23.2.1'
    compile 'com.android.volley:volley:1.0.0'
    compile 'com.google.firebase:firebase-core:9.2.0'
    compile 'com.google.firebase:firebase-messaging:9.2.0'
    compile 'de.hdodenhof:circleimageview:2.1.0'
    compile 'com.android.support:design:23.2.1'
    compile "com.android.support:recyclerview-v7:23.2.1"
    compile 'com.android.support:cardview-v7:23.2.1'
    compile 'com.google.android.gms:play-services-maps:9.4.0'
}

在这些依赖下面我放

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

但我无法构建应用,因为会返回此错误。

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.2.0.

所以我试着把

compile 'com.google.android.gms:play-services-maps:9.2.0'

应用程序构建,所以我的问题是: 为什么我无法使用最新版本的services-map

5 个答案:

答案 0 :(得分:3)

将此行添加到build.gradle

的末尾
apply plugin: 'com.google.gms.google-services' 

并添加此类路径(其他build.gradle

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

答案 1 :(得分:2)

昨天我遇到了同样的问题并通过以下方式解决了这个问题:

首先,确保您的项目/顶级gradle文件具有依赖项内谷歌服务的最新版本

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

其次,请确保将插件放在gradle app文件的底部

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

并确保包括firebase在内的所有Google服务依赖项属于同一版本,即9.4.0

compile 'com.google.android.gms:play-services:9.4.0'
compile 'com.google.android.gms:play-services-auth:9.4.0'
compile 'com.google.android.gms:play-services-gcm:9.4.0'

compile 'com.google.firebase:firebase-core:9.4.0'
compile 'com.google.firebase:firebase-auth:9.4.0'

这是我目前在app.gradle依赖项中的内容。

答案 2 :(得分:1)

这是因为你正在使用

compile 'com.google.firebase:firebase-core:9.2.0'
compile 'com.google.firebase:firebase-messaging:9.2.0'

正如您可以在这些依赖项的pom文件中找到的那样:

 <artifactId>firebase-analytics</artifactId>
  <version>9.4.0</version>
  <packaging>aar</packaging>
  <dependencies>
    <dependency>
      <groupId>com.google.android.gms</groupId>
      <artifactId>play-services-basement</artifactId>
      <version>9.2.0</version>
      <scope>compile</scope>
      <type>aar</type>
    </dependency>

他们正在使用带有9.2.0的com.google.android.gms库。

使用

compile 'com.google.firebase:firebase-core:9.4.0'
compile 'com.google.firebase:firebase-messaging:9.4.0'

答案 3 :(得分:0)

确保在根build.gradle中拥有最新的插件引用。

此外,如果您最近更新了播放服务并且所有引用都很好 - 尝试通过调用rm -rf ~/.gradle/cache来清理gradle缓存,有时它会有所帮助

buildscript {
    repositories {
        jcenter()
    }

    dependencies {
        //...
        classpath 'com.google.gms:google-services:3.0.0'
    }
}

答案 4 :(得分:-1)

改变这个:

compile 'com.google.firebase:firebase-core:9.2.0'
compile 'com.google.firebase:firebase-messaging:9.2.0'

通过

compile 'com.google.firebase:firebase-core:9.4.0'
compile 'com.google.firebase:firebase-messaging:9.4.0'