google-services.json: Complete Setup Guide for Android & Firebase

10 min readAndroid & Firebase

Introduction

If you're building an Android app with Firebase, you've encountered google-services.json. This configuration file is essential for connecting your app to Firebase services like Analytics, Cloud Messaging, Authentication, and more. This guide explains what the file contains, how to generate it, where to place it, and how to troubleshoot common issues.

What is google-services.json?

google-services.json is a configuration file that the Google Services Gradle plugin uses to initialize Firebase and other Google services in your Android app. It contains:

  • project_info - Firebase project details (project ID, number, storage bucket)
  • client - App-specific configuration (package name, API keys, OAuth clients)
  • configuration_version - File format version

Here's what a typical file looks like:

{
  "project_info": {
    "project_number": "123456789012",
    "firebase_url": "https://my-project.firebaseio.com",
    "project_id": "my-project",
    "storage_bucket": "my-project.appspot.com"
  },
  "client": [
    {
      "client_info": {
        "mobilesdk_app_id": "1:123456789012:android:abc123def456",
        "android_client_info": {
          "package_name": "com.example.myapp"
        }
      },
      "oauth_client": [
        {
          "client_id": "123456789012-abc.apps.googleusercontent.com",
          "client_type": 3
        }
      ],
      "api_key": [
        {
          "current_key": "AIzaSyC..."
        }
      ],
      "services": {
        "appinvite_service": {
          "other_platform_oauth_client": []
        }
      }
    }
  ],
  "configuration_version": "1"
}

How to Generate google-services.json

Method 1: Firebase Console (Recommended)

  1. Go to the Firebase Console
  2. Create a new project or select an existing one
  3. Click the Android icon to add an Android app
  4. Enter your app's package name (must match your applicationId in build.gradle)
  5. Optionally enter your app's SHA-1 fingerprint for Authentication and Dynamic Links
  6. Click "Register app" and download the google-services.json file

Method 2: Using Our Online Tool

If you already know your Firebase project details, you can generate a valid google-services.json using our Google Services JSON Tool. This is useful for:

  • Quickly generating a file for testing
  • Recreating a lost google-services.json
  • Validating an existing file for errors

Where to Place the File

The google-services.json file must be placed in the correct location for the Gradle plugin to find it:

my-android-app/
├── app/
│   ├── google-services.json   ← Place it here!
│   ├── build.gradle.kts
│   └── src/
├── build.gradle.kts
└── settings.gradle.kts

The file goes in your app/ module directory, NOT the project root. If you have multiple product flavors, you can place different files in app/src/flavorName/google-services.json.

Gradle Configuration

You need to add the Google Services plugin to both your project-level and app-level build files:

Project-level build.gradle.kts

plugins {
  id("com.google.gms.google-services") version "4.4.2" apply false
}

App-level build.gradle.kts

plugins {
  id("com.android.application")
  id("com.google.gms.google-services")  // Add this line
}

dependencies {
  // Firebase BoM (Bill of Materials)
  implementation(platform("com.google.firebase:firebase-bom:33.1.0"))
  implementation("com.google.firebase:firebase-analytics")
  implementation("com.google.firebase:firebase-messaging")
}

Common Issues and Fixes

Error: "File google-services.json is missing"

The file is not in the app/ directory. Make sure it's named exactlygoogle-services.json (not google-services(1).json from downloading twice).

Error: "No matching client found for package name"

The package_name in google-services.json doesn't match your app'sapplicationId in build.gradle. They must be identical. Check for typos or different package names in flavor-specific build files.

Firebase services not working after adding the file

Make sure you've added the Google Services plugin to BOTH build.gradle files. Also, clean and rebuild the project after adding the file: ./gradlew clean build.

Multiple apps in one project

A single google-services.json can contain multiple client entries for different apps. When you add a new Android app to your Firebase project and download the file again, it will include all existing apps plus the new one.

Security Considerations

  • Can I commit google-services.json to Git? - Generally yes. The API keys inside are restricted to your app's package name and SHA-1 certificate, so they can't be used by others.
  • Restrict API keys - In the Google Cloud Console, ensure your API keys are restricted to your app's package name and signing certificate.
  • Use different projects for dev/prod - Create separate Firebase projects for development and production environments.
  • Never hardcode sensitive values - The google-services.json file is for configuration, not secrets. Use Firebase Remote Config or environment variables for sensitive data.

Validating Your google-services.json

If you're having issues, use our Google Services JSON Tool to validate your file. It checks for:

  • Valid JSON syntax
  • Required fields (project_info, client array)
  • Missing package names
  • Missing API keys
  • Correct structure and nesting

Key Takeaways

  • google-services.json is required for Firebase integration in Android apps
  • Generate it from the Firebase Console or use our online tool
  • Place it in your app/ directory, not the project root
  • The package_name must match your applicationId exactly
  • Add the Google Services plugin to both build.gradle files
  • It's generally safe to commit to version control, but restrict your API keys

Related Resources