Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Flutter and app store releases

Flutter Android: Failed to load FirebaseOptions from resource

ErrorPlatformException(java.lang.Exception, Failed to load FirebaseOptions from resource. Check that you have defined values.xml correctly., null, null)

Short answer

On Android, Firebase reads its settings from a values.xml file that the Google services Gradle plugin builds from google-services.json. If the plugin is not applied, the JSON file is missing or has the wrong package name, that file is never made. Fix the Gradle setup, or pass options from firebase_options.dart.

  • Applies to Flutter 3.x, firebase_core 3.x, Android Gradle Plugin 8.x
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Build the debug app, then look for the generated values.xml. If it is missing, the plugin did not run, which is the first cause.

    flutter build apk --debug
    ls android/app/build/generated/res/google-services/debug/values/
  2. 2Match what you see, then jump to its fix

    1. 1No values.xml under build/generated/res/google-servicesThe Google services Gradle plugin is not appliedFix
    2. 2File google-services.json is missing, or the build runs but no values.xml is generated for a flavor or build typegoogle-services.json is missing or in the wrong folderFix
    3. 3The plugin finds no client entry with your package name, so it throws an exception, or resources such as gcm_defaultSenderId are missingThe package name in the JSON does not match the appFix
    4. 4The error appears at startup while google-services setup is correct, or you use FlutterFire configurationFirebase.initializeApp is called without optionsFix

What does the error look like?

  • PlatformException(java.lang.Exception, Failed to load FirebaseOptions from resource. Check that you have defined values.xml correctly., null, null)
  • Failed to load FirebaseOptions from resource. Check that you have defined values.xml correctly.

Cause 1 of 4

The Google services Gradle plugin is not applied

1Check

The plugin turns google-services.json into values.xml. Search both Gradle files for its id.

grep -rn "com.google.gms.google-services" android/

2Fix

Declare the plugin with its version and apply false in the project-level file, then apply it without a version in android/app. Use the version shown on the Firebase setup page.

// project-level plugins block (version as in the Firebase docs)
id("com.google.gms.google-services") version "4.6.0" apply false

// android/app/build.gradle.kts
plugins {
    id("com.android.application")
    id("com.google.gms.google-services")
}

3Verify

Rebuild and check that values.xml now exists.

flutter clean
flutter build apk --debug
ls android/app/build/generated/res/google-services/debug/values/

Confirmed by firebase.google.com

Did this fix it?

Cause 2 of 4

google-services.json is missing or in the wrong folder

1Check

The default place is app/google-services.json. A build type or flavor can have its own copy under app/src.

find android/app -name google-services.json

2Fix

Download the file again from the Firebase console and put it in android/app, or in android/app/src/{build_type} when that build type uses a separate Firebase project.

cp ~/Downloads/google-services.json android/app/google-services.json

3Verify

Run the build again.

flutter build apk --debug

Confirmed by firebase.google.com

Did this fix it?

Cause 3 of 4

The package name in the JSON does not match the app

1Check

The plugin only uses the client entry whose package name matches your app. Compare the two values.

grep -n "applicationId" android/app/build.gradle*
grep -n "package_name" android/app/google-services.json

2Fix

Register the exact application id in the Firebase console and download a fresh google-services.json.

# Firebase console > Project settings > Your apps > add Android app with the applicationId, then download the file

3Verify

Rebuild after replacing the file.

flutter clean && flutter build apk --debug

Confirmed by firebase.google.com

Did this fix it?

Cause 4 of 4

Firebase.initializeApp is called without options

1Check

flutterfire configure writes lib/firebase_options.dart. Check that main.dart passes it.

ls lib/firebase_options.dart
grep -n "initializeApp" -A 3 lib/main.dart

2Fix

Run flutterfire configure and pass DefaultFirebaseOptions.currentPlatform to initializeApp.

flutterfire configure

// lib/main.dart
await Firebase.initializeApp(
  options: DefaultFirebaseOptions.currentPlatform,
);

3Verify

Run the app on Android and watch for the exception.

flutter run

Confirmed by firebase.google.com

Did this fix it?

How do I stop it coming back?

  • Commit google-services.json and firebase_options.dart together so they always match.
  • Re-run flutterfire configure whenever you add a platform, flavor or Firebase product.
  • After changing the applicationId, register the new id in Firebase and download the JSON again.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.