【问题标题】:after adding google-services.json also i am getting error like添加 google-services.json 后,我也收到类似的错误
【发布时间】:2016-03-21 12:28:50
【问题描述】:

GoogleService 初始化失败,状态:10,缺少预期的资源:用于初始化 Google 服务的“R.string.google_app_id”。可能的原因是缺少 google-services.json 或 com.google.gms.google-services gradle 插件。

这是我的项目 gradle 文件

// Top-level build file where you can add configuration options common to        all sub-projects/modules.
     apply plugin: 'maven-publish'
     apply plugin: "java"


     buildscript {
     repositories {
    jcenter()
   }
dependencies {

    classpath 'com.android.tools.build:gradle:2.1.0-alpha3'
    classpath 'com.google.gms:google-services:2.0.0-alpha5'

}

}

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

   task sourceJar(type: Jar) {
     from sourceSets.main.allJava
     classifier "sources"
   }

  publishing {
       publications {
    mavenJava(MavenPublication) {
        from components.java
        artifact sourceJar
        pom.withXml {
            asNode().appendNode('description', 'A demonstration of Maven  POM customization')
        }
    }
}
    }

这是我的 app.gardle

apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'
 android {
    compileSdkVersion 23
     buildToolsVersion '23.0.2'

defaultConfig {

    minSdkVersion 14
    targetSdkVersion 23
    versionCode 1
    versionName "1.0"
    multiDexEnabled true
    vectorDrawables.useSupportLibrary = true
    generatedDensities = []
}

aaptOptions {
    additionalParameters "--no-version-vectors"
}

buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}

dexOptions {
    preDexLibraries = false
    javaMaxHeapSize "4g"
}
  }

 dependencies {
     compile fileTree(include: ['*.jar'], dir: 'libs')
      compile files('libs/universal-image-loader-1.9.5.jar')
      compile project(':databaseAutoCompleteLibrary')
    compile 'com.android.support:support-v4:23.2.0'
   compile 'com.android.support:gridlayout-v7:23.2.0'
    compile project(':MPChartLib')
    compile project(':filechooserlibrary')
   compile 'com.android.support:design:23.2.0'
   compile 'com.android.support:support-v13:23.2.0'
   compile 'com.android.support:appcompat-v7:23.2.0'
   compile project(':Volley')
   compile 'com.google.code.gson:gson:2.4'
   compile 'com.loopj.android:android-async-http:1.4.9'
   compile 'com.jakewharton:butterknife:7.0.1'
   compile 'com.baoyz.swipemenulistview:library:1.3.0'
   compile 'milyn:opencsv:1.6'
   compile 'de.hdodenhof:circleimageview:2.0.0'
   compile 'com.squareup.picasso:picasso:2.5.2'

   compile 'com.google.android.gms:play-services:8.3.0'
   compile 'com.android.support:multidex:1.0.1'

  }

【问题讨论】:

  • 你添加了gradle插件吗?
  • 在添加 gradle 插件后,它也给出了错误,例如 Error:(4, 0) Plugin with id 'com.google.gms.google-services' not found.
  • 你在应用程序的buil.gradle和projec gradle文件中定义了正确的jar文件和插件吗??
  • @user6076314 参考这里coderzpassion.com/android-working-latest-google-plus-login-api 用图片一步步解释得很漂亮。希望你能找到你的错误
  • 我已经创建了密钥..是否需要再次创建它?

标签: android android-studio google-play-services


【解决方案1】:

在你的 app build.gradle 文件中应用它

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

dependencies {
    compile 'com.google.android.gms:play-services:8.3.0'
  }

在你的项目 build.gradle 中定义

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:1.2.3'
        classpath 'com.google.gms:google-services:1.5.0-beta2'
    }
}

allprojects {
    repositories {
        jcenter()
    }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-09-18
    • 1970-01-01
    • 2015-11-11
    相关资源
    最近更新 更多