Proactive firebase with FirebaseOptions

I want to initialize Firebase using FirebaseOptions without google-services.json, I follow the blog post here https://firebase.googleblog.com/2017/03/take-control-of-your-firebase-init-on.html .

I uninstalled FirebaseInitProvider.

<provider android:name="com.google.firebase.provider.FirebaseInitProvider" android:authorities="${applicationId}.firebaseinitprovider" tools:node="remove"/> 

I am trying to set the default FirebaseApp in a subclass of Application:

 FirebaseOptions options = new FirebaseOptions.Builder() .setApplicationId("valid_app_id") .setGcmSenderId("valid_gcm_sender_id") .setApiKey("valid_api_key") .build(); FirebaseApp.initializeApp(getApplicationContext(), options); 

Everything seems to be in order, but when I want to record some events in FirebaseAnalytics, I get this error: Missing google_app_id. Firebase Analytics is disabled. I do not know what the problem is.

+7
android firebase firebase-analytics
source share
1 answer

If you are not using the google-services.json file, the information that is present in JSON must be somewhere to read the plugin / code. Here you can create the xml file manually with a string resource with the following attributes:

 google_app_id: {YOUR_CLIENT}/client_info/mobilesdk_app_id gcm_defaultSenderId: project_info/project_number default_web_client_id: {YOUR_CLIENT}/oauth_client/client_id (client_type == 3) ga_trackingId: {YOUR_CLIENT}/services/analytics-service/analytics_property/tracking_id firebase_database_url: project_info/firebase_url google_api_key: {YOUR_CLIENT}/api_key/current_key google_crash_reporting_api_key: {YOUR_CLIENT}/api_key/current_key 

Take a look here . Remember to add google_app_id , but that will not lead to the error in question.

If you do not have the namespace "tools" added to your root manifest tag, you also need to add this:

 <manifest xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" package="your.package" > 

The rest of the implementation will be the same using FirebaseOptions and Firebase.InitializeApp().

-one
source share

All Articles