-
Notifications
You must be signed in to change notification settings - Fork 612
Initialize FirebaseApp without google-services.json #66
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
@paularius could you try adding a string entry to your project (in <!-- 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 |
@samtstern Thanks for your reply. |
@paularius you're right that you shouldn't need the XML file at all. Where are you calling |
@samtstern I call it first thing in onCreate, in my application class. |
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 |
@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.. |
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. |
Having the same issue. Will be there any fix soon? |
@samtstern Any news here? |
@samtstern Any update on this issue? |
|
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 #187 (comment) Thanks for the question and for waiting patiently. Many Firebase SDKs products provide an overload that allows you to pass in a custom 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 The challenge with designing an API like 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.
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. |
Duly noted. This feedback is helpful for us to prioritize. |
It was a wonderful time to work with the Fabric, until google bought it. Logs when trying to build a release project:
Please rollback to previous build project feature, like it was with Fabric. Update:Here is a tested workaround, how to to init crashlytics and firebase when you need:
For analytics:
I created a test crash with this solution and found the report in the dashboard. |
Workaround when you have generated xml file, but not google-services plugin itself: val copyGoogleIdValuesTask = tasks.register("copyGoogleIdValues", Copy::class.java) {
from("src/main/res/values/google-services.xml")
into("${project.buildDir}/generated/res/google-services/values.xml")
}
tasks.withType<com.google.firebase.crashlytics.buildtools.gradle.tasks.UploadMappingFileTask>() {
dependsOn(copyGoogleIdValuesTask)
} May not work in multivariant apps. |
Is there any update on this problem wrt. Firebase Analytics, as of September 29th, 2020. I'm having to solve the exact same problem, and I'm out of solutions. Does anyone else have any other way by which this problem can be solved? |
Workaround (groovy syntax) when you have generated xml file located in task copyGoogleIdValuesTask(type: Copy) {
from 'src/release/res/values/values.xml'
into "$project.buildDir/generated/res/google-services/release/values/"
}
import com.google.firebase.crashlytics.buildtools.gradle.tasks.UploadMappingFileTask
tasks.withType(UploadMappingFileTask).configureEach {
dependsOn(copyGoogleIdValuesTask)
} Works for release build variant. |
Any update on this? Still facing this issue in March of 2021 😩 |
Still facing this issue in December of 2021. They resolved 926 issues. But this 66th issue is open for over 3 years. |
Any update on this? |
Still no solution for this? March 2022 :( |
Hi, we've implemented a workaround for use of Firebase Analytics. We've not tested any other usage. Your milage may vary. Overview It appears the actual analytics code is implemented in play-services-measurement-*.jar files (which I assume are downloaded automatically via Google Play Services). To initialise Firebase I call the following programmatically: FirebaseOptions.Builder builder = new FirebaseOptions.Builder()
.setApplicationId(FirebaseConstants.APP_ID)
.setApiKey(FirebaseConstants.API_KEY)
.setGcmSenderId(FirebaseConstants.MESSAGING_SENDER_ID)
.setProjectId(FirebaseConstants.PROJECT_ID);
FirebaseApp.initializeApp(getContext(), builder.build());
FirebaseAnalytics.getInstance(getContext()); The context provided by Implementation Add the following to your private FirebaseResourcesWrapper firebaseResources;
@Override
public Resources getResources() {
if (firebaseResources == null)
firebaseResources = new FirebaseResourcesWrapper(super.getResources());
return firebaseResources;
} The public class FirebaseResourcesWrapper extends Resources {
private static final String GOOGLE_APP_ID = "google_app_id";
private static final int R_STRING_GOOGLE_APP_ID = 1_999_999_999;
private final Resources wrapped;
public FirebaseResourcesWrapper(Resources wrapped) {
super(wrapped.getAssets(), wrapped.getDisplayMetrics(), wrapped.getConfiguration());
this.wrapped = wrapped;
}
public int getIdentifier(String name, String defType, String defPackage) {
if (GOOGLE_APP_ID.equals(name) && "string".equals(defType))
return R_STRING_GOOGLE_APP_ID;
return wrapped.getIdentifier(name, defType, defPackage);
}
public String getString(int id) throws NotFoundException {
if (id == R_STRING_GOOGLE_APP_ID)
return FirebaseConstants.APP_ID;
return wrapped.getString(id);
}
public String getString(int id, Object... formatArgs) throws NotFoundException {
return wrapped.getString(id, formatArgs);
} Full implementation of https://gist.github.com/electricbolt/423c03f09bc0303d0d5696b8beb392bd |
Any update on this? |
Any update on this issue? |
👋 |
Hi @ashwinraghav, have there been any updates on a fix for this issue? |
Any news on this issue? |
Same issue here. 5-6 years later, still no plan to fix it? Using this workaround seems to work. |
@sergey-avagyan @Hunter54 |
Thanks for your solution. I've got one question, how do you define FirebaseConstants? In my app, while initializing flutter app I pull secrets from secrets manager, save it in FlutterSecureStorage and initialize FirebaseApplication with appropriate secrets pulled in previous step. Firestore and crashlytics work fine, but analytics don't. The solution proposed by you looks promising, but I'm missing one part, how to share these secrets in FirebaseResourcesWrapper class. I would be grateful if you could share your ideas! |
We have something similar to the following, just standard constant definitions. Since your app is distributed publicly, it's available for anyone to inspect internally by downloading the APK file and disassembling. Your constants are never truly private. You could obfuscate your strings using an external tool, and embedding the obfuscated text, then have a deobfuscate() method to return the plain text. Commercial obfuscation tools include DexGuard, dProtect, DashO etc. public final class FirebaseConstants {
} |
Hello @electricbolt, we have a similar issue since we have to manage two different Firebase projects within our app. The first Firebase Project is used to send events to GA4 (projectID 1) while the other Firebase is about crashlytics and notifications (projectID 2). We tried the approach you suggested, but we observed that in our case when the projectID 1 is initialized programmatically it doesn't work. Could you please confirm that your Firebase tracking GA4 events? More over, which value do you set in the Firebase constants (es: Thanks, |
Yes working fine for us. We have the following: @Override
public boolean onCreate() {
Log.d(TAG, "FirebaseInitContentProvider initializing");
FirebaseOptions.Builder builder = new FirebaseOptions.Builder()
.setApplicationId(FirebaseConstants.APP_ID())
.setApiKey(FirebaseConstants.API_KEY())
.setGcmSenderId(FirebaseConstants.MESSAGING_SENDER_ID())
.setProjectId(FirebaseConstants.PROJECT_ID());
FirebaseApp.initializeApp(getContext(), builder.build());
FirebaseAnalytics.getInstance(getContext());
return false;
} And the FirebaseConstants is like this: public final class FirebaseConstants {
public static String API_KEY() {
if (Config.SIMULATOR) {
return '...';
} else {
return '...';
}
}
public static String APP_ID() {
if (Config.SIMULATOR) {
return '...';
} else {
return '...';
}
}
public static String MESSAGING_SENDER_ID() {
if (Config.SIMULATOR) {
return '...';
} else {
return '...';
}
}
public static String PROJECT_ID() {
if (Config.SIMULATOR) {
return '...';
} else {
return '...';
}
}
} Our app doesn't actually have a strings.xml file. But if you did, you don't need to put the R_STRING_GOOGLE_APP_ID into it because that's what the gist above is doing - capturing the getString calls and allowing them to be done programmatically. |
<string name="com.google.firebase.crashlytics.mapping_file_id">none</string> <string name="com.crashlytics.android.build_id">1</string> If you have any trouble, please check example here: https://github.com/hungnb94/hide-firebase-api-keys-example |
We are also looking for a way to dynamically provide the If I am not wrong, that issue/limitation does not exist on iOS. This issue is opened for years with 62 thumbs-up, any chance we can bring more attention to this ticket and move the discussion forward ? |
[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) :
I do not have a google-services.json file in my project, I have removed the FirebaseInitProvider, like this, in my AndroidManifest.xml:
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 .
The text was updated successfully, but these errors were encountered: