Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter Firebase setup & Missing google_app_id. Firebase Analytics disabled

I created a new Flutter app with the command flutter create test9_firebase_setup -a kotlin --platforms android. The goal is to connect to firebase with auth, analytics and crashlytics working.

In my pubspec.yaml, I have added:

dependencies:
  # ...
  firebase_core: ^2.17.0
  firebase_analytics: ^10.5.1
  firebase_crashlytics: ^3.3.7
  firebase_auth: ^4.10.1

My main() function looks like that. After initialization of firebase, we sign in anonymously just to check that it works. The result of the authentication is printed in the console. Then we initiate Crashlytics and we log an entry in Analytics. Those snippets are coming straight from the doc, so they should work.

Future<void> main() async {
  WidgetsFlutterBinding.ensureInitialized();

  await Firebase.initializeApp(
    options: DefaultFirebaseOptions.currentPlatform,
  );

  final user = await FirebaseAuth.instance.signInAnonymously();
  print(
    user.user?.isAnonymous == true ? 'You are signed in' : 'Can\'t sign in',
  );

  FlutterError.onError = (errorDetails) {
    FirebaseCrashlytics.instance.recordFlutterFatalError(errorDetails);
  };

  PlatformDispatcher.instance.onError = (error, stack) {
    FirebaseCrashlytics.instance.recordError(error, stack, fatal: true);
    return true;
  };

  await FirebaseAnalytics.instance.logBeginCheckout(
    value: 10.0,
    currency: 'USD',
    items: [
      AnalyticsEventItem(
        itemName: 'Socks',
        itemId: 'xjw73ndnw',
        price: 10.0,
      ),
    ],
    coupon: '10PERCENTOFF',
  );

  runApp(const MyApp());
}

I enabled Authentication, Crashlytics and Analytics in my firebase console. And then I ran flutterfire configure. This created the firebase_options.dart and the google-services.json.

I'd like to point out that I skipped the SDK instructions given by firebase during the configuration of the android app in the console, because (as I understood from some third-party tutorials I followed) these steps should be automatically done by flutterfire configure. Therefore I did not do any manual modification of build.gradle at this point.

When I run my app, I can see the You are signed in line in my console. And indeed I can see a new anonymous user in my console on the web. So that means that the connection with Firebase works.

I saw several tutorials and articles on the web were people were running flutterfire configure and everything was working. But apparently not for me, because I get the Missing google_app_id. Firebase Analytics disabled error in my console.

I tried triggering an Exception in my UI but the Crashlytics dashboard did not show anything.

Then I updated my build.gradle file manually. I added the following lines in the app level build.gradle file:

dependencies {
    implementation(platform("com.google.firebase:firebase-bom:32.3.1"))
    implementation("com.google.firebase:firebase-analytics-ktx")
    implementation("com.google.firebase:firebase-auth-ktx")
}

Now, crashlytics seems to be working, but I still get the Missing google_app_id. Firebase Analytics disabled. error. And in fact my 'Realtime Analytics' and 'Analytics Dashboard' pages on the firebase console do not show any activity.

I went back to the SDK Instructions given by Firebase during the project setup and I tried to do them manually. My project was setup with kotlin and they tell me to look for a build.gradle.kts file. But I only have build.gradle files. I tried anyway:

  • I don't have any plugins {} in my root-level buildgradle file, so I tried adding this but then I get the error Plugin [id: 'com.google.gms.google-services', version: '4.4.0', apply: false] was not found in any of the following sources: [...]
  • The same error is obtained if I add in my app-level build.gradle file the line below. The dependencies section was already filled out (as said above) and is working.
plugins {
    id "com.android.application"
    id "kotlin-android"
    id "dev.flutter.flutter-gradle-plugin"
    // Add this:
    id "com.google.gms.google-services"
}

So, 3 questions:

  • Why do I have build.gradle files and not build.gradle.kts files even though my flutter project was setup with kotlin?
  • Shouldn't flutterfire configure automatically update build.gradle and add the required dependencies?
  • Can anyone recommend steps to enable Google Analytics?

Thanks!

like image 351
RedLamp15 Avatar asked Jul 18 '26 15:07

RedLamp15


2 Answers

I got the same issue and in my case it's solved by

com.google.gms:google-services:4.3.14 instead of 
com.google.gms:google-services:4.4.0
like image 86
Minahil Fayyaz Avatar answered Jul 21 '26 05:07

Minahil Fayyaz


If you're using Flutterfire to configure new Firebase projects, there are several things necessary to deal with this issue:

  1. android/app/build.gradle, please follow Firebase Analytics's configuration.
plugins {
    id "com.android.application"
    id "kotlin-android"
    id "dev.flutter.flutter-gradle-plugin"
    id "com.google.gms.google-services" // add this line
}

dependencies {
     // Import the Firebase BoM
  implementation platform('com.google.firebase:firebase-bom:32.7.0')


  // TODO: Add the dependencies for Firebase products you want to use
  // When using the BoM, don't specify versions in Firebase dependencies
  implementation 'com.google.firebase:firebase-analytics'
}
  1. android/build.gradle
buildscript {
    // TODO: you may need to update the kotlin_version
    ext.kotlin_version = '1.9.22'
    repositories {
        google()
        mavenCentral()
    }

    dependencies {
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        // TODO: you may need to update the gms_version
        classpath 'com.google.gms:google-services:4.4.0'
    }
}
  1. android/settings.gradle
plugins {
    id "dev.flutter.flutter-plugin-loader" version "1.0.0"
    // TODO: you may need to update this plugin version if you are using a newer Flutter version.
    id "com.android.application" version "7.4.2" apply false
}
like image 24
Woden Avatar answered Jul 21 '26 04:07

Woden



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!