11

I have multiple Android apps that all include a custom library. This library is the core of the apps, and each app just contains a main activity extending an activity from the library to decide which flavour the specific app has.

I now want to include Firebase Analytics in the whole app, including the library, but I cannot wrap my head around how to. The google-services.json file should be different for each app, but I can not include the google-services plugin without a google-services file containing the library's package name.

I hope you have som ideas.

Thank you!

2
  • I would love to have someone else opinion too, but afaik this is currently not supported by Firebase.
    – Sistr
    Commented Aug 9, 2016 at 12:24
  • I think I may have found a solution, but as the data has not come in yet I can't be sure. I will post when I know for sure.
    – Anddev
    Commented Aug 10, 2016 at 14:54

1 Answer 1

10

You should add the google-services.json file and apply the google-services plugin to your app module, not the library project.

Most of the resources generated by the plugin are used dynamically and won't be necessary for the library to compile. However, if the library does use one of those resources explicitly (and therefore can't compile without it), the library can include a placeholder resource in its own strings.xml file which will eventually be overridden by the properly configured app.

5
  • 1
    This is almost what I did. I followed the tutorial and set everything up in the app module. Then I added compile 'com.google.firebase:firebase-core:9.4.0' to the library's build.gradle. Everything seems to work, and I can see my events in the Firebase console. I forgot to mention that I send my events from the library.
    – Anddev
    Commented Aug 11, 2016 at 9:01
  • Hi @Anddev, I have a library(myLibrary) which is built by me. I have integrated myLibrary into one of my project. Both library and project has analytics. I can see events in project but not in library. I have different projects in firebaes for library and project. Can u help me out in this.
    – Tara
    Commented Feb 4, 2020 at 10:57
  • Hi @Tara, I do not have access to the code base anymore, and have not been developing anything requiring a custom library in Android since my post, so I’m afraid I can’t be much of a help. All I remember is having to add Firebase to the library’s build.gradle. If you are using analytics from both library and project, I would guess you need a separate key for each.
    – Anddev
    Commented Feb 5, 2020 at 12:28
  • Thanks for response @Anddev. but would like to clear that if someone responds! I have created separate projects in firebase for both(project and library) in different accounts. As I have different projects with diff accounts so I will have diff jsons and keys.as well.
    – Tara
    Commented Feb 5, 2020 at 13:03
  • So if I want to offer an SDK to others, and want to also track some things there (including Crashlytics, to fix bugs), how can I do it? Can't be done with Crashlytics/Analytics of Firebase? Commented May 29 at 6:51

Not the answer you're looking for? Browse other questions tagged or ask your own question.