java - 尝试将 Firebase 添加到 Android Studio 项目,但它不会添加(应用程序 :processDebugGoogleServices Error)

标签 java android firebase google-play-services

我一直在尝试将 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/

相关文章:

java - 如何使用 Java 库根据数组属性过滤 Google Content Store 数据

Android studio 3 和 Gradle 3.0.0 - 依赖项具有不同的编译和运行时类路径版本

android - 即使在调用 onDestroy() 之后,Android 服务是否仍然存在?

java - Class<SomeObject> 是否只有一个实例?

java - 获取数组错误和流条件的键

android - Getview在android中被多次调用

firebase - 文档引用会增加阅读次数吗?

Firebase 身份验证 - 过期的 api key

java - 在 ListView 中显示来自 Firebase 的数据时出错

java - 在方法级别而不是类级别的基本 Jax-RS PATH 配置