Search code examples
androidfirebasefirebase-remote-config

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!


Solution

  • 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.