Search code examples
androidfirebasefirebase-analyticsfirebase-crash-reporting

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?


Solution

  • 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