Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set up Firebase Crashlytics for Debug and Release mode

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?

like image 408
gryzek Avatar asked Jan 01 '23 07:01

gryzek


1 Answers

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)

like image 197
Alex Avatar answered Jan 13 '23 14:01

Alex