I tried connecting my Android project with Firebase but JSON file error is coming

Viewed 152

this is my build.gradle(.app) file

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'



}

this is my build.gradle(movie booking app) file

// 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 is the file which I have added

this is error is coming.

 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

I tried many other approaches, I also searched that the file is added or not, all I have searched, I don't know where I went wrong.

1 Answers

I ran into this issue at the start when I created my project. Make sure you have the proper json file added. Your current json file says "google-services(1).json". The app doesn't recognize the (1) and so it thinks it is a different file. Rename that to "google-services.json" and your code should work. It' kinda annoying that they are treated differently and I spent a lot of time at the start working this out too.

Before: google-services(1).json

After: google-services.json

Related