androidflutterfirebasefirebase-analytics

Flutter Firebase: Missing google_app_id


Recently I have added firebase to my flutter project. I used the dart, flutter fire and firebase CLI to initialize the project by following the steps below.

$ dart pub global activate flutterfire_cli
$ flutterfire configure --project=<my project ID>

then added the firebase packages by running

$ flutter pub add firebase_core
$ flutter pub add firebase_analytics

In my main.dart I have initilaized firebase as follows

void main()  async{
  WidgetsFlutterBinding.ensureInitialized();
  await Firebase.initializeApp(
    options: DefaultFirebaseOptions.currentPlatform,
  );
}

To test if everything was working fine I added the a log in my MyApp() as follows

...
static FirebaseAnalytics analytics = FirebaseAnalytics.instance;
...
@override
  Widget build(BuildContext context) {
    analytics.logAppOpen();

When I run my app i get the following error in my console

Missing google_app_id. Firebase Analytics disabled. See https:...

I have tried adding the plugins manualy in my settings.gradel as follows

plugins {
    id "dev.flutter.flutter-plugin-loader" version "1.0.0"
    id "com.android.application" version "7.3.0" apply false
    id "org.jetbrains.kotlin.android" version "1.9.23" apply false
    id 'com.google.gms.google-services' version '4.4.1' apply false

}

my app/build.gradel

plugins {
    id "com.android.application"
    id "kotlin-android"
    id "dev.flutter.flutter-gradle-plugin"
    id 'com.google.gms.google-services'
}
...
flutter {
    source '../..'
}

dependencies {
    implementation platform('com.google.firebase:firebase-bom:32.8.0')
    implementation 'com.google.firebase:firebase-analytics'
}

I have also checked my google-services.json for app-id and it is present.

"client": [
    {
      "client_info": {
        "mobilesdk_app_id": "X:XXXXXXXXX:android:XXXXXXXXXXXXX",
        "android_client_info": {
          "package_name": "XXX.XXXXXXXX.XXXXXX"
        }
      },

I have also tried the steps mentioned in Github and stackoverflow


Solution

  • I was able to solve the problem by adding

    implementation("com.google.firebase:firebase-analytics-ktx") in my app/build.gradel

    (Added it based on Flutter Firebase setup & Missing google_app_id. Firebase Analytics disabled)

    When I re run the application, the error went away and I was able to see the analytics event after few hours.

    Here is code for reference

    app/build.gradel

    flutter {
        source '../..'
    }
    
    dependencies {
        implementation platform('com.google.firebase:firebase-bom:32.8.0')
        implementation 'com.google.firebase:firebase-analytics'
        implementation("com.google.firebase:firebase-crashlytics")    //Firebase Crashlystic
        implementation("com.google.firebase:firebase-analytics-ktx")
    
    }
    

    gradel.settings

    pluginManagement {
        def flutterSdkPath = {
            def properties = new Properties()
            file("local.properties").withInputStream { properties.load(it) }
            def flutterSdkPath = properties.getProperty("flutter.sdk")
            assert flutterSdkPath != null, "flutter.sdk not set in local.properties"
            return flutterSdkPath
        }
        settings.ext.flutterSdkPath = flutterSdkPath()
    
        includeBuild("${settings.ext.flutterSdkPath}/packages/flutter_tools/gradle")
    
        repositories {
            google()
            mavenCentral()
            gradlePluginPortal()
        }
    }
    
    plugins {
        id "dev.flutter.flutter-plugin-loader" version "1.0.0"
        id "com.android.application" version "7.3.0" apply false
        id "org.jetbrains.kotlin.android" version "1.9.23" apply false
        id 'com.google.gms.google-services' version '4.3.15' apply false
        id "com.google.firebase.crashlytics" version "2.8.1" apply false
    
    }
    
    include ":app"