Reputation: 1017
The app I am working on has a very customized build process. It's not possible to use gradle to build my app. It's not ideal, but I cannot change anything about it.
Nevertheless, I want to use Firebase Analytics in my app. In included the modules firebase-core, firebase-common, firebase-analytics, firebase-analytics-impl, firebase-iid, firebase-iid-interop, firebase-measurement-connector, firebase-measurement-connector-imple, play-services-measurement-base and play-services-measurement-api. I also added the following strings to my strings.xml
, with the values I found in the google-services.json
for my Firebase project:
<string name="google_app_id" translatable="false">xxx</string>
<string name="gcm_defaultSenderId" translatable="false">xxx</string>
<string name="default_web_client_id" translatable="false">xxx</string>
<string name="firebase_database_url" translatable="false">xxx</string>
<string name="google_api_key" translatable="false">xxx</string>
<string name="google_crash_reporting_api_key" translatable="false">xxx</string>
<string name="project_id" translatable="false">xxx</string>
(as described here) and removed the FirebaseInitProvider
from the AndroidManifest.
In my apps Application
class onCreate()
I do:
FirebaseOptions.Builder builder = new FirebaseOptions.Builder()
.setApplicationId(getString(R.string.google_app_id))
.setApiKey(getString(R.string.google_api_key));
FirebaseApp.initializeApp(this, builder.build(), "[DEFAULT]");
No issues so far. When the above code is executed, I get a debug log message saying:
FirebaseApp: com.google.firebase.auth.FirebaseAuth is not linked. Skipping initialization.
All good, I didn't include the auth module. I don't need it for my app. When I call FirebaseAnalytics.getInstance(adblockSettingsTextView.getContext()).getFirebaseInstanceId()
it returns a String value, so I assume the initialization was successful.
Now every time I want to log an event like this
Bundle bundle = new Bundle();
bundle.putString(FirebaseAnalytics.Param.CONTENT_TYPE, "Dashboard");
FirebaseAnalytics.getInstance(this).logEvent(FirebaseAnalytics.Event.SELECT_CONTENT, bundle);
I see the an error in my log saying Missing google_app_id. Firebase Analytics disabled. See https://firebase.google.com/docs/android/setup.
On top of that, I don't see any active users in the Firebase Analytics dashboard.
I read all documents I could find and tried my best to find the cause for this problem. But right now I have no more ideas what I can check or change to make it work. Help would be highly appreciated. Thanks!
Upvotes: 3
Views: 1970
Reputation: 1017
In case someone else runs into the same issue, I leave the answer I got from the Firebase Support here:
Google Analytics for Firebase (GA4F) doesn't support dynamic initialization. Our engineers are checking the possible solutions to support this. It's just that we still haven't found a definite timeline as to when (or if) this will be available.
GA4F will not work without the google-services.json file (or Gradle on your end). Even though you can initialize the FirebaseApp dynamically through code, GA4F will not recognize this and will only result in the error message you are seeing. The scenario you are getting is only specific to Google Analytics for Firebase. However, you can still use other products like Firestore, Realtime Database, Storage even if you are not using Gradle plugin.
Upvotes: 7