【问题标题】:I tried connecting my Android project with Firebase but JSON file error is coming我尝试将我的 Android 项目与 Firebase 连接,但 JSON 文件错误即将到来
【发布时间】:2021-03-09 10:46:53
【问题描述】:

这是我的 build.gradle(.app) 文件

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


android {
    compileSdkVersion 29
    buildToolsVersion "29.0.3"

    defaultConfig {
        applicationId "com.example.moviebookingapp"
        minSdkVersion 27
        targetSdkVersion 29
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

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

dependencies {
    implementation fileTree(dir: "libs", include: ["*.jar"])
    implementation 'androidx.appcompat:appcompat:1.1.0'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    implementation 'androidx.cardview:cardview:1.0.0'
    implementation 'com.google.android.material:material:1.0.0'
    implementation 'androidx.gridlayout:gridlayout:1.0.0'
    implementation 'com.google.android.material:material:1.0.0'
    implementation 'com.google.firebase:firebase-database:19.5.1'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test.ext:junit:1.1.1'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
    implementation'com.android.support:recyclerview-v7:29.3.1'
    implementation 'com.basgeekball:awesome-validation:1.3'

    implementation 'com.google.firebase:firebase-analytics:18.0.0'
    implementation'com.google.firebase:firebase-database:19.5.1'



}

这是我的 build.gradle(电影预订应用程序)文件

// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:4.1.0'
        classpath "com.google.gms:google-services:4.3.4"



        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        google()
        jcenter()
    }
}

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

google-services(1).json 是我添加的文件

这是错误即将到来。

 Execution failed for task ':app:processDebugGoogleServices'.
> File google-services.json is missing. The Google Services Plugin cannot function without it. 
   Searched Location: 
  D:\ankita\android\moviebookingapp2\app\google-services.json
  D:\ankita\android\moviebookingapp2\app\src\nullnull\google-services.json
  D:\ankita\android\moviebookingapp2\app\src\debug\google-services.json
  D:\ankita\android\moviebookingapp2\app\src\nullnullDebug\google-services.json
  D:\ankita\android\moviebookingapp2\app\src\nullnull\debug\google-services.json
  D:\ankita\android\moviebookingapp2\app\src\debug\nullnull\google-services.json

我尝试了很多其他方法,我也搜索了该文件是否添加,我都搜索过,我不知道我哪里出错了。

【问题讨论】:

  • 第一件事,你有没有从你在firebase控制台中添加的项目中下载这个json文件?
  • 你可能需要从firebase下载最新的json文件
  • 是的,我只下载了最新版本
  • 你把那个文件放在 app 里了吗?目录?
  • 是的,我已放置

标签: android firebase android-studio android-layout firebase-realtime-database


【解决方案1】:

我在创建项目时遇到了这个问题。确保添加了正确的 json 文件。您当前的 json 文件显示“google-services(1).json”。该应用程序无法识别 (1),因此它认为它是一个不同的文件。将其重命名为“google-services.json”,您的代码应该可以工作。他们被区别对待有点烦人,而且我一开始也花了很多时间来解决这个问题。

之前:google-services(1).json

之后:google-services.json

【讨论】:

  • 是的,等一下,我会做你建议的改变
  • 谢谢兄弟检查我的答案。我 99% 确定它会起作用。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-06-13
  • 2020-06-05
  • 1970-01-01
  • 2019-10-04
  • 2019-04-20
相关资源
最近更新 更多