Lalit Kushwah
Lalit Kushwah

Reputation: 4049

How to add google-services.json in Android?

The error is:

File google-services.json is missing from module root folder. The Google Quickstart Plugin cannot function without it.

Upvotes: 73

Views: 235409

Answers (9)

Don Benito
Don Benito

Reputation: 31

  1. Download the "google-service.json" file from Firebase
  2. Go to this address in windows explorer "C:\Users\Your-Username\AndroidStudioProjects" You will see a list of your Android Studio projects
  3. Open a desired project, navigate to "app" folder and paste the .json file
  4. Go to Android Studio and click on "Sync with file system", located in dropdown menu (File>Sync with file system)
  5. Now sync with Gradle and everything should be fine

Upvotes: 2

Lalit Kushwah
Lalit Kushwah

Reputation: 4049

Above asked question has been solved as according to documentation at developer.google.com https://developers.google.com/cloud-messaging/android/client#get-config

2018 Edit : GCM Deprecated, use FCM

The file google-services.json should be pasted in the app/ directory. After this is when I sync the project with gradle file the unexpected Top level exception error comes. This is occurring because:

Project-Level Gradle File having

dependencies {
    classpath 'com.android.tools.build:gradle:1.0.0'
    classpath 'com.google.gms:google-services:1.3.0-beta1'
}

and App-Level Gradle File having:

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:22.1.1'
    compile 'com.google.android.gms:play-services:7.5.0' // commenting this lineworks for me
}

The top line is creating a conflict between this and classpath 'com.google.gms:google-services:1.3.0-beta1' So I make comment it now it works Fine and no error of File google-services.json is missing from module root folder. The Google Quickstart Plugin cannot function without it.

Upvotes: 33

Aravin
Aravin

Reputation: 7067

It should be on Project -> app folder

Please find the screenshot from Firebase website

enter image description here

Upvotes: 23

Kevin Kopf
Kevin Kopf

Reputation: 14210

This error indicates your package_name in your google-services.json might be wrong. I personally had this issue when I used

buildTypes {
    ...

    debug {
        applicationIdSuffix '.debug'
    }
}

in my build.gradle. So, when I wanted to debug, the name of the application was ("all of a sudden") app.something.debug instead of app.something. I was able to run the debug when I changed the said package_name...

Upvotes: 2

sivaBE35
sivaBE35

Reputation: 1891

WINDOWS

  1. Open Terminal window in Android Studio (Alt+F12 or View->Tool Windows->Terminal). Then type

"move file_path/google-services.json app/"

without double quotes.

eg

move C:\Users\siva\Downloads\google-services.json app/

LINUX

  1. Open Android Studio Terminal and type this

scp file_path/google-services.json app/

eg:

scp '/home/developer/Desktop/google-services.json' 'app/'

Upvotes: 3

Yash Agrawal
Yash Agrawal

Reputation: 464

Instead of putting in root folder as given in docs of firebase, just copy the google-json file in the projectname/app 's root folder and it works fine then . Its just simple !

Upvotes: 9

ViramP
ViramP

Reputation: 1709

google-services.json file work like API keys means it store your project_id and api key with json format for all google services(Which enable by you at google console) so no need manage all at different places.

Important process when uses google-services.json

at application gradle you should add

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

at top level gradle you should add below dependency

  dependencies {
        // Add this line
        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
    }

Upvotes: 0

Nari Kim Shin
Nari Kim Shin

Reputation: 2499

The document says:

Copy the file into the app/ folder of your Android Studio project, or into the app/src/{build_type} folder if you are using multiple build types.

Upvotes: 24

Gaganpreet Singh
Gaganpreet Singh

Reputation: 886

Click right above the app i.e android(drop down list) in android studio.Select the Project from drop down and paste the json file by right click over the app package and then sync it....

Upvotes: 2

Related Questions