How do I get Firebase's project name from Android? - android

I have an app with Firebase integrated. We switch back and forth between project "Development" and project "Production" in Firebase.
On Android, switching the project is done by replacing the google-services.json file. Is there any way I can get the Firebase's project name (i.e. Temu Production and Temu Development) from inside Android? Something like FirebaseApp.getInstance().getProjectName()?
I'm new to Firebase so I'm open to various approaches on project management and infrastructure.

The project name is provided by the FirebaseApp class.
Android:
FirebaseApp.getInstance().getOptions().getProjectId() should do the trick.
iOS (Swift):
FirebaseApp.app()?.options.projectID works well.

Related

library module and google-services.json files

I am already using an application(has app module) which uses conversations.im as the base. This application has free, paid etc product flavors and debug and release build types. This project already has firebase integration and has 2 applications integrated. I have one google-services.json file in the root directory of the app module.
Now I want to move away from conversations.im(ejabber) and want to implement a separate chat component using cloud firestore. I have created this component as an android library module which I will use in my existing app module.
I want to have separate chat data for this chat library for debug and release types. This will require me to have unique application ids for this library module. But documentation says I cannot have applicationId in a library module.
I am confused where to keep the google-services.json files, in library module or in the app module which will use the chat library module. Looks like can't keep in library because of limitation. And if I keep in app module, library chat module can't work as a separate module in itself.
How should I go about this setup so that I could use different google-services.json files for debug and release types and at the same time make this new module as a library.
Logically speaking, any android project should be able to use the library module and all the chat data should belong to the project and not tied to the chat library. If I go by this approach, google-services.json files should reside within the app module and not library module.
I figured out that we don't have to put the google-services.json file in the library module. We can keep them in the app module which uses the library module.
Now the next question is, is it possible to view data sent from different build variants of the same app under different application views so that we don't accidentally corrupt the test data and production data in firestore?
I have sorted this.
I had to create separate project to keep my firestore chat data for staging and production separate. This is because firebase console does not show the firestore chat data application wise. It shows the chat data project wise. Therefore irrespective of your app's build-variants, data will always flow into one firestore db. And just in case we want to keep our test and production data clean, creating a new firebase project is the only way out.
Thanks everyone for reading the question.

Can I use Firebase Remote config in an Android library module and still alow the library consumer to use it?

Is it possible to use Firebase Remote config in an Android library module and still allow the library consumer to use Firebase Remote Config with their own acount?
I have created an Android library that uses Firebase Remote Config to update the library configuration from my Firebase console account.
In my reference/test app that references the library I have my google-services.json in the app directory. Everything works perfectly.
I have just realised that once I provide my library to others as an aar they will potentially have their own google-services.json and use Firebase directly in their own app.
I have searched google but I'm finding it difficult to find out if this is even possible? Has anyone had experience with this setup or know how it should work? The only thing I could think of trying was moving my google-services.json into the library but I couldn't get this working.
Thanks in advance for any help!
Use of Firebase SDKs in third-party modules was never intended by the Firebase team. The SDKs all depend very heavily on a host project that's configured by the app as a whole, not by a module. In fact, you can't use the google-services plugin in the library module, only in an app module.
Remote Config is even more complicated in that it depends heavily on Analytics, which is definitely only viable as an app-level dependency (you can't have two projects collecting Analytics from a single app).
If you try really hard, you might be able to use something like Realtime Database in a third party module where all apps that use it all have access to the same database, but then you'd have to initialize a special FirebaseApp that points to your common project, and make your database world-readable, because you won't have Authentication in place to gate access to individual users.
Apparently now (I am using BOM 26.0.0, but I think it was available since some prior versions) you can ALSO setup your Firebase instance manually, instead of it being read automatically from the google-services.json.
If you dig into their code you can find overloaded methods for
FirebaseApp getInstance()
FirebaseApp getInstance(#NonNull String name)
Which you can setup manually using this overloaded method:
FirebaseApp initializeApp(#NonNull Context context, #NonNull FirebaseOptions options, #NonNull String name)
Being FirebaseOptions a builder class where you can setup your values manually.

How do I structure my react-native JS code to have multiple android apps in the same project?

I just finished creating an android app in react-native (RN). I need to create another app now. A lot of code is same across both apps. I want to create the second app within the same project and reuse all the common components rather than duplicating them.
I went through this SO question and configure android build variants link. They talk about how to create a new module, gradle config and organization of java code in different source sets like src/demoDebug/, src/debug/, src/demo/ and src/main/.
I don't think this will work with react-native because the entry point of RN app is index.android.js. For 2 apps to work out of the same project we need 2 entry points. Is there a way to define multiple entry points in a RN android app? Does RN support this? If yes, how to organize files of the two apps in the same project?
you can create git submodule and move all shared code to it

Add Firebase App per package?

I am attempting to add Firebase Analytics and Crash Reporting to my app. I added the app in the Firebase Console. I made the updates to gradle and added the firebase core and crash reporting libs as dependencies.
My app is broken into multiple subprojects. Each has a slightly different package name:
app/org.mythtv.android.app
tv/org.mythtv.android.tv
presentation/org.mythtv.android.presentation
domain/org.mythtv.android.domain
data/org.mythtv.android.data
app and tv are two high-level subprojects that separate the app from the android tv version, presentation is common components for the 2 previous interface layers, domain encapsulates the interaction with common logic when dealing with data, and data is where the interaction with the backend occurs.
They all share a common package: org.mythtv.android
The application id is org.mythtv.android.
I created an app in the Firebase Console based on org.mythtv.android and added the google-services.json to the root of app and tv. I then wanted to track the crash reports in the other layers as well. Gradle fails to build at this point as it can't find packages org.mythtv.android.presentation and org.mythtv.android.data. These are both Android Library subprojects. data is just a java subproject.
Does the Firebase console need to have a separate app per package and each needs its own separate google-services.json? Doesn't this kind of defeat the purpose?
It sounds like you already got to the root of the problem, which is that you're only supposed to copy the google-service.json apply the google services plugin to application projects, not library projects. The plugin wants to make some changes that are only relevant for apps.
To help others with the same problem, the error message looks like this:
* What went wrong:
Execution failed for task ':mylibrary:processReleaseGoogleServices'.
> No matching client found for package name 'com.google.mylibrary'
Where "mylibrary" is the name of your own library project.
To be honest, I think the plugin should detect if it's being applied to a library project and fail instead with a better message, so I'll see if we can get that remedied.
As an aside, you may want to consider merging your two app projects into a single app project with two different flavors, one for app and the other for tv. They can then share everything by default, but have separate configurations to target different API levels and even have different sets of resources, assets, manifest items, and even independent code, if you're careful. This should simplify the structure of your project. You can read build variants here:
http://tools.android.com/tech-docs/new-build-system/user-guide
Firebase Analytics reports based on the application package name. The package name is not related to the packages you use for your Java classes. The two are independent. The application package name is used by Android to identify your app (for update for example) and can not be changed once you release your app. If you are using gradle you can find it in your app/build.gradle as applicationId value or in your AndroidManifest.xml package attribute.

Cloud Endpoints Generated library not found

I am creating a backend GAE project with Cloud Endpoints. I want also to create an Android application that will consume these endpoints, and I found in the documentation here that I have to copy the java source classes to my Android project to access to the endpoints. I really don't like this approach thinking in the case that I am developing the endpoints for a external client (I don't want to give them my source code, I prefer just give them a jar library to avoid complexity).
I found reading the README file also generated with the endpoints that The generated service-specific library can be found in the top level directory
of the zip file:
google-api-services-noteendpoint-v1-rev20130920182043-1.16.0-rc.jar. But this jar is not generated anymore.
So, copying the source classes is the only way to pass the access to the endpoint to the Android project? Where is this jar that once was supposed to be created?
Thanks so much.
Ok, I found the answer, the jar is not generated but can be generated by maven. The endpoints created has maven structure and you only have to package it to get the final jar. Tested and working.
On eclipse, with Google plugin, clicking on the appengine project you can select:
Google->Generate Cloud Endpoint Client Library, you need to have an associated android project. You can create a android associated project, selecting, when creating a new project: AppEngine Connected Android Project.

Categories

Resources