Android Studio - 将com.google.android.gms版本更新为11.6.0

时间:2017-11-10 05:23:33

标签: android android-studio gradle

我总是在我的android工作室得到这个错误,我对此没有任何想法,我试图在互联网上找到解决方案,但我仍然无法找到它。

这是我的Gradle Image:

enter image description here

这是错误图片:

enter image description here

2 个答案:

答案 0 :(得分:6)

在您的项目中,错误就像您没有添加项目级别谷歌类路径而在应用级别中不应用谷歌插件 gradle so,

添加项目级gradle

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

添加APP级别gradle和google插件

  dependencies {

      compile 'com.google.firebase:firebase-core:11.6.0'
      compile 'com.google.android.gms:play-services:11.6.0'

   }
     //  ADD THIS AT THE BOTTOM
     apply plugin: 'com.google.gms.google-services'

注意 - 如果您想根据需要添加更多Google gradle,请使用相同版本添加。

更多 https://firebase.google.com/docs/android/setup

https://developers.google.com/android/guides/setup

答案 1 :(得分:0)

如果您使用的是Google服务,那么您的Gradles应该是这样的:

应用程序级build.gradle应该看起来像

apply plugin: 'com.android.application'
apply plugin: 'com.google.firebase.firebase-crash'
android {

    compileSdkVersion 26
    buildToolsVersion "26.0.2"
    defaultConfig {
        applicationId "com.xxxxxx"
        minSdkVersion 15
        targetSdkVersion 26
        versionCode 11
        versionName "1.10"
        multiDexEnabled true
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            signingConfig signingConfigs.config
        }
        debug {
            signingConfig signingConfigs.config
            resValue("string", "PORT_NUMBER", "8081")
        }
    }
    dexOptions {
        javaMaxHeapSize "4g"
    }
}

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'
    })
    debugCompile project(':debug-db')
    compile project(':tracker')
    compile 'com.android.support:appcompat-v7:26.1.0'
    compile 'com.android.support:design:26.1.0'
    compile 'com.android.support:cardview-v7:26.1.0'
    compile 'com.android.support:multidex:1.0.2'
    compile 'com.google.android.gms:play-services-location:11.6.0'
    compile 'com.google.android.gms:play-services-places:11.6.0'
    compile 'com.google.android.gms:play-services-maps:11.6.0'
   /* compile 'com.google.android.gms:play-services:11.6.0'*/
    compile 'com.google.firebase:firebase-core:11.6.0'
    compile 'com.google.firebase:firebase-crash:11.6.0'
    compile 'com.google.firebase:firebase-messaging:11.6.0'
    compile 'com.mcxiaoke.volley:library:1.0.19'
    compile 'com.squareup.okhttp3:okhttp:3.8.0'
    compile 'de.hdodenhof:circleimageview:2.1.0'
    compile 'com.squareup.retrofit2:retrofit:2.3.0'
    compile 'com.squareup.retrofit2:converter-gson:2.3.0'
    compile 'com.android.support.constraint:constraint-layout:1.0.2'
    compile 'com.android.support:recyclerview-v7:26.1.0'
    testCompile 'junit:junit:4.12'
}
// Add to the bottom of the file
apply plugin: 'com.google.gms.google-services'

正如您所看到的,没有用于构建,但它完全取决于您的使用/* compile 'com.google.android.gms:play-services:11.4.0'*/

根级gradle.build是:

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    repositories {
        jcenter()
        mavenCentral()
        google()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.0.0'
        classpath 'com.google.gms:google-services:3.1.1'
        classpath 'com.google.firebase:firebase-plugins:1.1.1'
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        maven { url "https://jitpack.io" }
        jcenter()
        mavenCentral()
        google()
    }
}

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

确保gradle-wrapper.properties中的Gradle分布是

distributionUrl=https\://services.gradle.org/distributions/gradle-4.3-all.zip