Reputation: 5565
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
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
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:
google-services.json
apply plugin: 'com.google.gms.google-services'
(and related things)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:
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'
Upvotes: 5
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