How to fix messaging/invalid-package-name: Package name doesn't match in Firebase

FirebaseINTERMEDIATEHIGHUpdated Dec 22, 2025ยท 182 views

This error occurs when your Android app's package name doesn't match the one registered in your Firebase project configuration. The mismatch prevents Firebase Cloud Messaging from identifying your app correctly.

Quick fix

Fixes messaging/invalid-package-name: Package name doesn't match

// android/app/build.gradle
android {
    defaultConfig {
        applicationId "com.example.myapp"  // This is your package name
        // ...
    }
}
  1. Verify your app's actual package name
  2. Check the package name in google-services.json
  3. Update Firebase Console or download correct config file
  4. Handle build variants with multiple package names
firebase โ€” error
// android/app/build.gradle
android {
defaultConfig {
applicationId "com.example.myapp" // This is your package name
// ...
}
}
messaging/invalid-package-name: Package name doesn't match

What this error means

The "invalid-package-name" error in Firebase Cloud Messaging indicates that there's a discrepancy between your Android application's actual package name and the package name registered in your Firebase project configuration. Firebase uses the package name as a unique identifier to associate your app with the correct Firebase project and configuration. When you initialize Firebase services, it validates that the package name in your app matches one of the package names registered in the google-services.json configuration file. If no match is found, or if another Firebase/Google Cloud project already has an OAuth 2.0 client ID with your package name and SHA-1 combination, this error is thrown. This validation is critical for security and ensures that Firebase Cloud Messaging tokens and messages are delivered to the correct application. The package name must match exactly - even differences in capitalization or additional characters will cause this error.

Typical symptoms

  • Firebase Cloud Messaging fails to initialize in your Android app
  • Push notifications are not received despite correct server-side setup
  • App crashes or throws exception during Firebase initialization
  • Error appears in logs: "messaging/invalid-package-name: Package name doesn't match"
  • Build fails with message about no matching client found for package name

Common causes

  1. Package name in build.gradle applicationId doesn't match the package name registered in Firebase Console
  2. The google-services.json file was downloaded for a different Firebase project or app
  3. Using build variants (flavors/build types) with applicationIdSuffix but only one google-services.json file
  4. Package name in AndroidManifest.xml doesn't match the Firebase configuration
  5. Another Firebase or Google Cloud project already uses your package name with the same SHA-1 fingerprint
  6. Typo or incorrect capitalization in the package name when registering the app in Firebase Console

How to fix "messaging/invalid-package-name: Package name doesn't match"

1Verify your app's actual package name

First, identify the package name your app is actually using. Open your app's build.gradle file and check the applicationId:

gradle
// android/app/build.gradle
android {
    defaultConfig {
        applicationId "com.example.myapp"  // This is your package name
        // ...
    }
}

Also verify the package attribute in your AndroidManifest.xml:

xml
<!-- android/app/src/main/AndroidManifest.xml -->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.myapp">
    <!-- ... -->
</manifest>

Note the exact package name including capitalization - it must match exactly.

2Check the package name in google-services.json

Open your google-services.json file (located at android/app/google-services.json) and find the package_name field:

json
{
  "project_info": { ... },
  "client": [
    {
      "client_info": {
        "mobilesdk_app_id": "1:123456789:android:abc123...",
        "android_client_info": {
          "package_name": "com.example.myapp"
        }
      }
    }
  ]
}

Compare this package_name with the one from step 1. They must match exactly.

3Update Firebase Console or download correct config file

If the package names don't match, you have two options:

Option A: Update your app's package name (if Firebase is correct):
1. Update the applicationId in build.gradle to match Firebase
2. Update the package in AndroidManifest.xml
3. Refactor your code directory structure if needed
4. Clean and rebuild: ./gradlew clean

Option B: Update Firebase Console (if your app is correct):
1. Go to Firebase Console (https://console.firebase.google.com)
2. Select your project
3. Go to Project Settings > General
4. Find your Android app in the "Your apps" section
5. If the package name is wrong, delete the app and re-add it with the correct package name
6. Download the new google-services.json file
7. Replace the old file in your project at android/app/google-services.json

After updating, rebuild your app completely.

4Handle build variants with multiple package names

If you use build variants (flavors or build types) that add an applicationIdSuffix, you need separate Firebase apps and config files:

gradle
// android/app/build.gradle
android {
    buildTypes {
        debug {
            applicationIdSuffix ".debug"
            // This creates package: com.example.myapp.debug
        }
        release {
            // This uses: com.example.myapp
        }
    }
}

For this scenario:
1. Register each variant as a separate app in Firebase Console:
- com.example.myapp (release)
- com.example.myapp.debug (debug)
2. You'll get one google-services.json with multiple client entries, or
3. Use different config files per variant using gradle:

gradle
android {
    buildTypes {
        debug {
            applicationIdSuffix ".debug"
        }
    }
}

// Copy the appropriate google-services.json based on build type
task switchToDebug {
    doLast {
        copy {
            from 'google-services-debug.json'
            into 'app'
            rename { 'google-services.json' }
        }
    }
}
5Verify and clean build cache

After making changes, ensure all build caches are cleared:

bash
# Clean Gradle cache
cd android
./gradlew clean

# Clear build folders
rm -rf app/build
rm -rf build

# For React Native projects
cd ..
rm -rf node_modules
npm install

# For Flutter projects
flutter clean
flutter pub get

Then rebuild your app completely:

bash
# Android
./gradlew assembleDebug

# React Native
npx react-native run-android

# Flutter
flutter run
6Test Firebase initialization

Verify the fix by checking Firebase initialization in your app:

kotlin
// Android (Kotlin)
import com.google.firebase.Firebase
import com.google.firebase.messaging.FirebaseMessaging

class MainActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        // Test FCM token retrieval
        FirebaseMessaging.getInstance().token.addOnCompleteListener { task ->
            if (task.isSuccessful) {
                val token = task.result
                Log.d("FCM", "Token retrieved successfully: $token")
            } else {
                Log.e("FCM", "Failed to get token", task.exception)
            }
        }
    }
}

If the token is retrieved successfully, your package name configuration is correct.

Advanced notes

SHA-1 Fingerprint Conflicts: In rare cases, the error "invalid-package-name" can occur if another Firebase or Google Cloud project contains an OAuth 2.0 client ID with both the same package name AND SHA-1 fingerprint that you're trying to use. This typically happens when migrating between projects or working across multiple development teams. To resolve this, you'll need to either use a different package name or remove the conflicting OAuth client from the other project.

Multiple Firebase Projects: If you're working with multiple Firebase projects (e.g., development, staging, production), ensure you're using the correct google-services.json for each environment. Consider using separate build flavors for each environment with their own configuration files.

Cordova/Ionic/Capacitor Projects: For hybrid mobile frameworks, the package name is typically defined in config.xml (Cordova/Ionic) or capacitor.config.json (Capacitor). Ensure these match your Firebase configuration. The google-services.json should be placed in the platform-specific directory (e.g., platforms/android/app/ for Cordova).

React Native Firebase: When using @react-native-firebase, the package name is defined in android/app/build.gradle. The library automatically reads from google-services.json, so ensure both files are in sync. If using Flipper or other dev tools, they may add applicationIdSuffix which requires separate Firebase app registration.

Monorepo Considerations: In monorepo setups where multiple apps share configuration, be careful not to accidentally use the wrong google-services.json file. Consider using environment-specific directories or build scripts to ensure the correct file is copied during build time.

Frequently asked questions

What does "messaging/invalid-package-name: Package name doesn't match" mean?
The "invalid-package-name" error in Firebase Cloud Messaging indicates that there's a discrepancy between your Android application's actual package name and the package name registered in your Firebase project configuration. Firebase uses the package name as a unique identifier to associate your app with the correct Firebase project and configuration. json configuration file.
How do I fix "messaging/invalid-package-name: Package name doesn't match"?
This error occurs when your Android app's package name doesn't match the one registered in your Firebase project configuration. The mismatch prevents Firebase Cloud Messaging from identifying your app correctly.
What causes "messaging/invalid-package-name: Package name doesn't match"?
Package name in build.gradle applicationId doesn't match the package name registered in Firebase Console The google-services.json file was downloaded for a different Firebase project or app Using build variants (flavors/build types) with applicationIdSuffix but only one google-services.json file
Is the "messaging/invalid-package-name: Package name doesn't match" error serious?
Yes. This is a high-severity error that usually blocks work until it is fixed, but the steps above resolve it.

Official resources & further reading