Adding Firebase Crashlytics either crash in runtime or fail unit test build
Asked Answered
C

3

6

I'm trying to add Firebase Crashlytics to a new Android app (single module, no flavors). Since Crashlytics is missing from the IDE assistant plugin, I'm using setup steps from https://firebase.google.com/docs/crashlytics/get-started:

  • add gradle dependencies
  • download google-services.json and put it in the /app root

Crashlytics is initialized for release builds only like this:

class MyApplication: Application() {

  fun onCreate() {
    super.onCreate()
    Fabric.with(
        this,
        Crashlytics.Builder()
            .core(CrashlyticsCore.Builder().disabled(BuildConfig.DEBUG).build())
            .build()
    )
  }
}

The problem #1: app crashes during initialization with

java.lang.RuntimeException: Unable to get provider com.crashlytics.android.CrashlyticsInitProvider: io.fabric.sdk.android.services.concurrency.UnmetDependencyException: The Crashlytics build ID is missing. This occurs when Crashlytics tooling is absent from your app's build configuration. Please review Crashlytics onboarding instructions and ensure you have a valid Crashlytics account.

Adding

<meta-data
  android:name="io.fabric.ApiKey"
  android:value="{blah-blah-key}" />

to AndroidManifest.xml fixes the issue (I'm seeing crashes in firebase console), but now I'm getting

Problem #2: running unit tests (gradle test) fails with

> Task :app:fabricGenerateResourcesRelease FAILED
ERROR - Crashlytics Developer Tools error.
java.lang.IllegalArgumentException: Crashlytics found an invalid API key: blah-blah-key

TL;DR - gradle fails to run unit tests if Fabric api key is present in manifest, app crashes in runtime if it's not present. I suspect that I'm doing something wrong, but not sure what exactly :(

Chalcanthite answered 6/3, 2019 at 8:29 Comment(2)
Did you resolve this? I have the same errorSelenite
Nope :( I think that introducing separate Application classes for debug and release build types (with crashlytics configuration only in release) should fix the issue, but I haven't tried that yetChalcanthite
B
13

I had a similar problem.

java.lang.RuntimeException: Unable to get provider com.crashlytics.android.CrashlyticsInitProvider: io.fabric.sdk.android.services.concurrency.UnmetDependencyException: The Crashlytics build ID is missing. This occurs when Crashlytics tooling is absent from your app's build configuration. Please review Crashlytics onboarding instructions and ensure you have a valid Crashlytics account.
        at android.app.ActivityThread.installProvider(ActivityThread.java:6288)

In my case it was because I forgot to add apply plugin: 'io.fabric' in /app/build.gradle

I did everything exactly according to the instructions and my application was able to send reports to Crashlytics. And I didn't add a io.fabric.ApiKey.

Bourguiba answered 5/4, 2019 at 7:17 Comment(3)
are you able to run gradle test?Chalcanthite
@MykhailoGaidai, yes. BUILD SUCCESSFUL. Need to mark that I have applicationIdSuffix ".debug" in my project for debug build. So I also added application com.myapp.debug in firebase console (in same project) and in google-services.json in client array. At first there was only com.myapp. I'm trying to set up getting errors in a debug build.Bourguiba
@AnatolySamoylenko adding apply plugin: 'io.fabric' in /app/build.gradle worked for meDouma
V
4

Well in my case:

classpath 'com.google.firebase:firebase-crashlytics-gradle:2.0.0-beta01'

was missing in project level build.gradle and

apply plugin: 'com.google.firebase.crashlytics'

was missing in the app-level build.gradle file

Venule answered 30/1, 2020 at 10:3 Comment(0)
E
0

For problme 1, I fix my crash problem with add below code in build.gradle.

The build.gradle in project level:

buildscript {
...
    }
    dependencies {
        classpath 'com.google.firebase:firebase-crashlytics-gradle:2.6.1'
        ...
    }
}

The build.gradle in app level:

apply plugin: 'com.google.firebase.crashlytics' // Apply the Crashlytics Gradle plugin
...
dependencies {
    // Declare the dependencies for the Crashlytics and Analytics libraries
    // When using the BoM, you don't specify versions in Firebase library dependencies
    implementation 'com.google.firebase:firebase-crashlytics'
    // Import the Firebase BoM
    implementation platform('com.google.firebase:firebase-bom:26.8.0')
    ...
}
Exscind answered 28/6, 2021 at 7:21 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.