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.
Related
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.
All!
I am building 2 android apps: one for each type of user and want to use as much shared code as possible. So I made 3 modules. One library module with shared code com.example and 2 application modules: com.example.one and com.example.two. Both application modules depend on the library module.
I want to put FCM into the library module. Is that possible? Will it work with only one google-services.json file? How should I configure my project in Firebase console?
it is possible ,
1)first step to create project in firebase
2) then you can see add app button in that firebase project.
3) then add app for your first app then
4) again add app for to add your second app
5) now generate service.json file ,which file used for your both apps you can copy that file in your both app directory.
Assume we have two executable module (A and B) and one library module which is C.
We want to A and B depended on C. If C has another dependencies like FCM, A and B also will depend on them over C. This is called transitive dependency.
You need add lines given below to your A's and B's gradle files.
dependencies {
...
compile project(':your_module_name(C in this example)')
}
If want to run separate modules on A & B (assume they dont depend each other, like a tablet and phone application because why not?) You need extra source sets configuration on gradle.
Good luck
Emre
In Android Studio 3 there are at least two new module types. First is Instant app module and the second one is feature module. With Instant App module it's quite obvious but feature module from my perspective is the same as the library module. So what is the real difference between library and feature modules and when I should use library module and when feature module?
I would complete Marcin Orlowski scheme like this.
You could picture library module in the same way as dependencies of a given feature or base module.
Hence the library modules will not be packaged in Instant APP APK.
A feature module is a module that applies com.android.feature plugin.
This module type has a dual nature:
When consumed by an application (com.android.application) during build, it produces an aar and works just like a library
When consumed by an Instant App APK (com.android.instantapp), it generates an Instant App APK
Developers should write feature modules just like library modules. The tools provided are responsible for applying the correct nature when used during a build.
In the simplest case an Instant app can have a single feature module.
If there is more than one feature module, these feature-to-feature
dependencies can be defined through the api configuration. In any
case, there must only be a single base feature which is marked with a
baseFeature attribute.
Main source: https://codelabs.developers.google.com/codelabs/android-instant-apps/#3
This all for Instant Apps so you only need it if you are making your app supporting instant app feature
See https://developer.android.com/topic/instant-apps/getting-started/structure.html#basic-app
Android SDK is the core features and software tools that allow you to create an app for the Android Platform. An SDK contains lots of libraries and tools which you will use to develop your application.
A Library is a collection of pre-built compiled code which you can use to extend your application's features. For example, you may need to show some graphics in your application. Instead of creating this from scratch, you may choose to use a pre-built library someone else has developed which will give you the features you need thus saving you some time.
A module is a small part of the application which can be tested and debugged on its own without needing the whole application. This is same for any programming language. Suppose you are building an app with Login feature. To test if the login feature works, you don't need the whole app. Thus the Login part is a module of your application.
The app module builds an app. A library module builds a library.
An app is what a user uses. The output of an app module is an APK, the package of an Android application.
A library is a collection of code that represents something that you want to use in multiple applications or otherwise want to keep in a separate "container" than the rest of the app code. The output of a library module is an AAR And Jar.
Use Feature for linked feature of your instant app (to launch it with deeplink).
Use Library for code dependency in your app or in your Feature modules.
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.
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.