gegobyte
gegobyte

Reputation: 5565

Is it required to add Firebase Analytics to build.gradle?

I am following the instructions here to add Firebase to my Flutter project. I want to use Firebase Analytics so I added it in pubspec.yaml

The package page for Firebase Analytics does not mention anything about adding Analytics as a dependency in android/app/build.gradle

No such thing is mentioned in Firebase for Flutter page either which I linked earlier. Now when registering the app in Firebase Console, it asks to add implementation of Firebase Analytics in app level build.gradle

Flutter Firebase Analytics

So do I need to add it or not as it looks like only Firebase Console wants me to add it but couldn't find any mention of it on any official Flutter page.

Upvotes: 5

Views: 1698

Answers (2)

madhead
madhead

Reputation: 33471

I had the same question as well. Is seems obvious, that you should add the dependency on com.google.firebase:firebase-analytics to your project.

But… You actually don't need it.

It's easy to test! Just set up the Firebase Analytics like it is described in the docs:

  1. google-services.json
  2. apply plugin: 'com.google.gms.google-services' (and related things)
  3. Configure multidex
  4. firebase_analytics: ^X.Y.Z in pubspec.yaml

Don't add any Firebase dependencies to you app/build.gradle!

Now, enable the DebugView in Firebase Analytics: adb shell setprop debug.firebase.analytics.app your.package.

Run the app and send some events. Open the DebugView in Firebase Analytics console and you'll see them all!

Probably, all the magic happens in the Google Services Gradle Plugin:

The google-services plugin has two main functions:

  1. Add dependencies for basic libraries required for the services you have enabled. …

    You can see the result of this step by running ./gradlew :app:dependencies.

So, the plugin seems to add them for you!

You could also check what dependencies will be autoconfigured, by running ./gradlew :projects from your android dir. Mine is:

Root project 'android'
+--- Project ':app'
+--- Project ':firebase_analytics'
\--- Project ':firebase_core'

Now, after I add firebase_auth to my pubspec.yml and run flutter pub get, this command indeed lists one extra project:

Root project 'android'
+--- Project ':app'
+--- Project ':firebase_analytics'
+--- Project ':firebase_auth'
\--- Project ':firebase_core'

enter image description here

Upvotes: 5

looptheloop88
looptheloop88

Reputation: 3810

Adding the Google Analytics for Firebase SDK in your app and enabling analytics settings in the Firebase console is optional. It depends on what Firebase product you will be using. If Firebase suggests you add the Analytics SDK, it means that the Firebase product has integration with Analytics. See this documentation for your reference.

Upvotes: 0

Related Questions