firebase-android-sdk
firebase-android-sdk copied to clipboard
Initialize FirebaseApp without google-services.json
- Android Studio version: 3.2
- Firebase Component: Core/Analytics(Database, Firestore, Storage, Functions, etc)
- Component version: 16.0.4
[REQUIRED] Step 3: Describe the problem
I am trying to initialize the FirebaseApp, only by using the FirebaseOptions builder, like this, first thing in my application (I use only applicationId and ApiKey, since I only want the analytics for start) :
FirebaseOptions options = new FirebaseOptions.Builder()
.setApplicationId(applicationID) // Required for Analytics.
.setApiKey(apiKey) // Required for Auth.
.build();
FirebaseApp.initializeApp(context, options);
I do not have a google-services.json file in my project, I have removed the FirebaseInitProvider, like this, in my AndroidManifest.xml:
<provider
android:name="com.google.firebase.provider.FirebaseInitProvider"
android:authorities="${applicationId}.firebaseinitprovider"
tools:node="remove"/>.
When starting the application, while trying to View events in the Android Studio debug log, like this: adb shell setprop log.tag.FA VERBOSE adb shell setprop log.tag.FA-SVC VERBOSE adb logcat -v time -s FA FA-SVC
I get Missing google_app_id. Firebase Analytics disabled. See https://goo.gl/NAOOOI .
@paularius could you try adding a string entry to your project (in strings.xml
)
<!-- Use the same value you used for applicationID above -->
<string name="google_app_id">YOUR_APPLICATION_ID</string>
For a more comprehensive guide on not using the json
file, see this blog post:
https://medium.com/@samstern_58566/how-to-use-firebase-on-android-without-the-google-services-plugin-93ecc7dc6c4
@samtstern Thanks for your reply. I have already tried this, and seems to work. The thing is that I would like to initialize the FirebaseApp more dynamically, since I would like to have different projects within the same apk (so using different flavors for the xml, would not be useful). I am trying a part of your approach and try to change the resource dynamically, using reflection, before initializeApp, but that doesn't seem to work either. Moreover, what is the use of the FirebaseOptions, if I have to use a file in my project?
@paularius you're right that you shouldn't need the XML file at all. Where are you calling InitializeApp()
and is it possible you're trying to use FirebaseAnalytics
before that happens?
@samtstern I call it first thing in onCreate, in my application class. Also, before I try to use any firebaseAnalytics call, I check that the FirebaseApp (the "[DEFAULT]" one) exists. But even if I tried to initialize it in some other place (for example when I get a response from my server), even by losing some events, should it be a problem?
I have had the same issue since months now. I have a running thread with the support team, and it doesn't look like this issue is going anywhere. In my scenario, I have the manual Firebase initialization in a library, and I have multiple apps that use that library. So based on the application thats using it, I initialize the Firebase app. Everything initializes well, but Firebase analytics, which complains about "Missing google_app_id".
We're having the same issue, really hope Firebase team moves faster on this as it's impacting many developers and we're considering moving off of Firebase due to it.
Thanks everyone for chiming in! I filed an internal bug (b/117609738) with the analytics team since they're likely not watching this issue as that SDK is still closed source. Hopefully they can help me get to the bottom of this.
If you'll let me take one more blind stab: what happens if you create a bogus google_app_id
string resource just to satisfy the SDK, but then initialize the default FirebaseApp
yourself at runtime. Does Analytics send events to the right place?
@samtstern if I just add a google app id, Firebase initializes the app on its own, but ofc doesn't add the other parameters like database url etc. So the manual initialization also fails, because it sees that the app has already been initialized. I even tried to add all the items as generated by firebase to my resources, as mentioned in this post: https://medium.com/@samstern_58566/how-to-use-firebase-on-android-without-the-google-services-plugin-93ecc7dc6c4. It works, but then like @paularius mentioned, I wouldn't be able to switch the app environments dynamically during run time.
Please, I have same problem with initialization app, is this problem solved yet, or exist any workaround?
There's no PR yet for that? How is going on the work to solve that?
I'm with the same problem, I want to load dynamically apps on runtime.
Is this issue fixed...I mean can we initialize firebase without this json file.. Also what is the purpose of firebaseoptions.builder if we can intialize firebase without the builder by simply copying the json file in project.
Yes, we have similar requirement where we would like to be able to switch on startup which Firebase project along with Analytics and Crashlytics should be used. Any feedback from Analytics teams on this?
Hi, we also have the same issue, it's stopping us from full migration from GA to Firebase because we need to setup Firebase in runtime with use of data received from our backend. Is there any ongoing work on this bug?
Having the same issue. Will be there any fix soon?
@samtstern Any news here?
@samtstern Any update on this issue?
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.
Just checking up on this, status of this has not changed, right?
@pepitoria AFAIK the last time we spoke with google - this issue is not going to be resolved.
bug with Firebase using in Chromium
in Chromium problem was due to string resources obfuscation (so google_app_id was obfuscated). adding resource_type/resource_name#no_obfuscate in aapt2.config solved problem
Copied from https://github.com/firebase/firebase-android-sdk/issues/187#issuecomment-635485459
Thanks for the question and for waiting patiently.
Many Firebase SDKs products provide an overload that allows you to pass in a custom FirebaseApp getInstance(FirebaseApp)
.
This API will allow you inject these Firebase instances as dependencies into your application code so they continue remaining agnostic to prod,staging,dev versions of your app.
I suspect your question pertains to eagerly initialized SDKs like Analytics, Crashlytics and Firebase Performance that require no developer interaction and start working automagically once included in the app. Note that these SDKs do not support the desired getInstance(FirebaseApp)
overload.
The challenge with designing an API like getInstance(FirebaseApp)
for these products is that it would have to be wired in super early in the App's lifecycle, to (say) allow Crashlytics to capture crashes that happen early on, or to (say) allow Performance to capture app start metrics early on.
In the absence of this API, you may be able to do this by disabling the default init provider and creating your own equivalent. The key here is to perform the custom initialization super early in your app's lifecycle, like in a Content Provider.
FirebaseOptions.Builder builder = new FirebaseOptions.Builder()
.setApplicationId("1:0123456789012:android:0123456789abcdef")
.setApiKey("your_api_key")
.setDatabaseUrl("https://your-app.firebaseio.com")
.setStorageBucket("your-app.appspot.com");
FirebaseApp.initializeApp(this, builder.build());
I realize is a suboptimal experience. It does get the job done for now. Feel free to propose ideas you may have to help up build an API to accommodate the nuance I described above.
Sadely @ashwinraghav this doesn't seem to solve the issue. We have struggled with this for almost two years. We have a multi-tenant application with dynamic switching of the firebase project and we got that working but analytics has to all be sent to one place by hardcoding "google_app_id" in values/strings.xml - this is the only thing that somewhat works. I just tried a Content Provider and the code runs fine but still see an error "Missing google_app_id." We continue to wait hopefully for one day a getInstance(FirebaseApp) for FirebaseAnalytics. Note this all works for the iOS SDKs.
Sadely @ashwinraghav this doesn't seem to solve the issue. We have struggled with this for almost two years. We have a multi-tenant application with dynamic switching of the firebase project and we got that working but analytics has to all be sent to one place by hardcoding "google_app_id" in values/strings.xml - this is the only thing that somewhat works. I just tried a Content Provider and the code runs fine but still see an error "Missing google_app_id." We continue to wait hopefully for one day a getInstance(FirebaseApp) for FirebaseAnalytics. Note this all works for the iOS SDKs.
Duly noted. This feedback is helpful for us to prioritize.
Is it possible to set up Firebase Cloud messaging from the instance of the second app ?
We are also affected from this issue since we are using a content provider instead of google-services.json
. We are trying to migrate to firebase crashlytics with mappingFileUploadEnabled
set to true. The build fails with the following error:
Crashlytics could not find the resource file generated by Google Services. You may need to execute the :process<Variant>GoogleServices Task. Please check your Firebase project configuration (https://firebase.google.com/docs/android/setup).
The issue is two years old and it is the highest voted firebase sdk github issue, shouldn't it have a top priority?
We are also affected from this issue since we are using a content provider instead of
google-services.json
. We are trying to migrate to firebase crashlytics withmappingFileUploadEnabled
set to true. The build fails with the following error:Crashlytics could not find the resource file generated by Google Services. You may need to execute the :process<Variant>GoogleServices Task. Please check your Firebase project configuration (https://firebase.google.com/docs/android/setup).
The issue is two years old and it is the highest voted firebase sdk github issue, shouldn't it have a top priority?
we're facing exactly the same problem with mappingFileUploadEnabled
I totally agree, this should have more priority.
Is it possible to set up Firebase Cloud messaging from the instance of the second app ?
We do use messaging successfully from the new app that we switch to.
The issue is two years old and it is the highest voted firebase sdk github issue, shouldn't it have a top priority?
Certainly is top priority :) We'll be sure to share our plans to address this issue with folks on this issue, to get some early feedback.
@ashwinraghav - does this mean a fix on the Android side is close? https://github.com/firebase/firebase-ios-sdk/pull/6142 - Not exactly related but going the right direction.