How to set up Firebase Crashlytics for Debug and Release mode
Asked Answered
C

1

7

I would like to set up crashlytics for debug and release mode but I can't find proper informations in firebase docs.

At now the app is in one project and there is only one crashlytics for debug and release. I can't create another app with the same package as a previous one. Another option is to have another project with the same package as the first one but I need to have one project due to api keys and other functionalities.

I have some two ideas but without a solution:

  1. One project -> two apps (with the same package? -> at now it doesn't work) -> two google-services.json and flavours.
  2. One project -> one app -> two setup of crashlytics for debug and release (how to do that?)

Does anyone have some some tips which could help to solve this case?

Coupling answered 11/2, 2020 at 9:3 Comment(3)
Try creating a different app with different package name <your package>.debug . And use the debug app google-services.json inside src/debug folder. Your app's build.gradle will look like this --- debug { \n applicationIdSuffix ".debug" \n debuggable true} --- Haven't tried it, and I don't have enough time for it. Please try and let know :)Unearth
@Unearth It doesn't work because I can't have two package names in one android app.Coupling
But the accepted answer says the same thing.Unearth
R
11

Both options are possible. However the first one would result in two separate Firebase projects, which is less managable. It's better to stick with one Firebase project and with the same app.

In short:

The package identifier should be different to make a difference between the debug and release variant in one project. We can distinct this by using the build type.

Next, the second identifier can be added to the Firebase project. Crashlytics will make the distinction between them in the app.


To achieve that, we can do the following.

1. In the Firebase Console

a. Go to the project settings.

b. Add an additional Android app with the following configuration:

  • App identifier: <app_identifier>.debug
  • Name: // (Anything), make sure to mark it with something like Debug at the end

c. Register this app

d. Download the google-services.json file, we will need it in the next step.

e. Go to the Crashlytics tab in the left menu

f. Enable Crashlytics for both the apps

  • Press Next at the second step
  • Ignore the third step, building the code will enable it

2. Android source

a. Place the google-services.json file in the project (under the app folder) -> Overwrite the old one

b. Open the app/build.gradle file.

  • Inside the android block, the buildTypes will be shown.
  • For the debug build type, add applicationIdSuffix '.debug' (add the debug type if it doesn't exist in the file)
  • This will cause the debug build type, to have .debug after the actual package identifier for the debug build.
  • Release builds will be unaffected by this

c. Result, it should look like this:

android {
    // ...

    buildTypes {
        debug {
            applicationIdSuffix '.debug'
        }
        release {
            // ...
        }
    }
}

3. Done!

Make a crash and it will result in the corresponding app in Firebase Crashlytics. There is a dropdown with both the projects at the top-left of the page.

Now, Crashlytics will automatically use the right Firebase app when sending a crash report. This works, since the google-services.json actually contains the configuration for both the build types. Crashlytics will use the right one based on the package identifier.

Last note: Don't forget enable Crashlytics at the Crashlytics tab in the Firebase Console (as described in step 1f)

Richert answered 11/2, 2020 at 20:21 Comment(3)
With this additional identifier - it seems to work fine :)Coupling
What is about other firebase products like , push notification, is this strategy will also work there?Sitra
Yeah, the other products like push notifications will also work fine with this configuration. As the Firebase project has the same server key, push will work fine for both build typesRichert

© 2022 - 2024 — McMap. All rights reserved.