Flutter Firebase setup & Missing google_app_id. Firebase Analytics disabled
Asked Answered
P

7

7

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!

Porter answered 7/10, 2023 at 12:5 Comment(0)
M
5

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
Myrticemyrtie answered 14/2, 2024 at 9:1 Comment(1)
It's very important to use version 4.3.14! Version 4.4.0 simply didn't compile for me.Injection
D
4

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
}
Darden answered 8/1, 2024 at 10:39 Comment(0)
S
2

There is a bug in flutterfire that makes it to not generate the correct setup

To fix it you must use flutterfire_cli 0.3.0-dev.19, check: https://github.com/firebase/flutterfire/issues/12078#issuecomment-1880725794

Sepulchral answered 30/1, 2024 at 23:25 Comment(1)
"There was a fix in flutterfire_cli 0.3.0-dev.19 for the android build.gradle updates."Recrement
G
1

A bug was fixed in flutterfire version 0.3.0-dev.19 (see Issue #12078)

You can check your version by running flutterfire --version If you need to update then run dart pub global activate flutterfire_cli 0.3.0-dev.19 --overwrite And then lastly run the following from your Flutter project directory: flutterfire configure (from guide Add Firebase to your Flutter app)

Goddard answered 7/2, 2024 at 15:29 Comment(0)
S
1

I solved this problem as follows.

android/build.gradle file:

plugins {
    id 'com.google.gms.google-services' version '4.3.15' apply false
}

allprojects {
    repositories {
        google()
        mavenCentral()
    }
}

rootProject.buildDir = '../build'
subprojects {
    project.buildDir = "${rootProject.buildDir}/${project.name}"
}
subprojects {
    project.evaluationDependsOn(':app')
}

tasks.register("clean", Delete) {
    delete rootProject.buildDir
}

app/build.gradle file:

plugins {
    id "com.android.application"
    id "kotlin-android"
    id 'com.google.gms.google-services'
    id "dev.flutter.flutter-gradle-plugin"
}
Smile answered 17/4, 2024 at 5:12 Comment(0)
M
0

I faced the same problem.

And this answer helped me: https://stackoverflow.com/a/77168724

I only needed to upgrade my Gradle dependency
From: classpath 'com.android.tools.build:gradle:7.3.1'
To: classpath 'com.android.tools.build:gradle:7.4.2'

Monmouth answered 13/10, 2023 at 22:6 Comment(2)
Thanks, sadly it does not change anything when I upgrade the Gradle dependency. And then, when I add classpath 'com.google.gms.google-services:4.4.0' (Firebase tells me to do that) everything crashes during build with the errorCould not find com.google.gms.google-services:4.4.0Porter
You need to add classpath 'com.google.gms:google-services:4.4.0' not classpath 'com.google.gms.google-services:4.4.0'Monmouth
F
0

Issue was actually happening on google-services version, I have been using

'com.google.gms:google-services:4.4.1'

change to

'com.google.gms:google-services:4.3.15' solved my issue

path : android/build.gradle

Fluvial answered 20/8, 2024 at 6:59 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.