我一直在尝试将 Firebase 添加到我的 android studio 项目中,但当我与 gradle 同步时,我不断遇到以下错误:
Error:Execution failed for task ':app:processDebugGoogleServices'.
> com.google.gson.JsonPrimitive cannot be cast to com.google.gson.JsonArray
这是我的两个 gradle 文件:
buildscript {
repositories {
jcenter()
mavenLocal()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.1.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()
mavenLocal()
}
}
和
apply plugin: 'com.android.application'
android {
packagingOptions {
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/NOTICE'
exclude 'META-INF/LICENSE'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
}
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
applicationId "com.platin.helpstl2"
minSdkVersion 16
targetSdkVersion 23
versionCode 6
versionName "1.6"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
productFlavors {
}
packagingOptions {
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/NOTICE'
exclude 'META-INF/LICENSE'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.google.android.gms:play-services:9.0.2'
compile 'com.google.maps.android:android-maps-utils:0.3+'
compile 'com.google.firebase:firebase-core:9.0.2'
}
apply plugin: 'com.google.gms.google-services'
我唯一一次可以成功与 gradle 同步的情况是,当我同时删除 classpath 'com.google.gms:google-services:3.0.0'
和 classpath 'com.google.gms:google-services:3.0.0'
时,因此我假设错误出在这两者之一。我已经按照 Firebase 网站上的说明进行操作,但运气不佳。
快速更新:实际上似乎错误现在是从 google-services json 文件发出的,因为调试错误发生在以下行之后:解析 json 文件:C:\Users\toshiba\AndroidStudioProjects\HelpSTL\app\google-services.json
感谢您的帮助,
雅各布
最佳答案
好吧,其实我自己解决了这个问题;问题在于您需要从 firebase 获取 google-services.json 文件。我刚刚重新下载并安装了该文件,现在它可以工作了!
关于java - 尝试将 Firebase 添加到 Android Studio 项目,但它不会添加(应用程序 :processDebugGoogleServices Error),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37707830/