0

I just wanted to disable crashlytics for debug build.

So I followed the instruction in their official document. https://docs.fabric.io/android/crashlytics/build-tools.html

According to the document, I have to do followings so I did it. First I added below,

android {
buildTypes {
    debug {
      // Disable fabric build ID generation for debug builds
      ext.enableCrashlytics = false
      ...

And I added below into my Application class.

// Set up Crashlytics, disabled for debug builds
Crashlytics crashlyticsKit = new Crashlytics.Builder()
.core(new CrashlyticsCore.Builder().disabled(BuildConfig.DEBUG).build())
.build();

// Initialize Fabric with the debug-disabled crashlytics.
Fabric.with(this, crashlyticsKit);

But I still get this error.

     Caused by: io.fabric.sdk.android.services.concurrency.UnmetDependencyException: This app relies on Crashlytics. Please sign up for access at https://fabric.io/sign_up,

Is there something that I'm missing?

I checked that the build type that I was trying to build and it worked well before without this configuration.

My crashlytics version is 2.9.4.

implementation 'com.crashlytics.sdk.android:crashlytics:2.9.4'

Thanks!

Lee Jeongmin
  • 793
  • 11
  • 22

4 Answers4

7

To disable Firebase before your application starts, you need to add the following code to your AndroidManifest.xml:

<application
    ... >

    ...

    <meta-data
        android:name="firebase_crashlytics_collection_enabled"
        android:value="${crashlyticsCollectionEnabled}" />

</application>

The expression ${crashlyticsCollectionEnabled} is called manifest placeholder and its value comes from your main module’s build. gradle file:

android {

...

buildTypes {
    debug {
        manifestPlaceholders = [crashlyticsCollectionEnabled:"false"]
        ...
    }

    release {
        manifestPlaceholders = [crashlyticsCollectionEnabled:"true"]
        ...
    }
}

}

tarun_sharma
  • 139
  • 1
  • 5
0

Looks like you are missing API Key, if yes then add in manifest file under application tag, like below

<application
      .........
      .........
      <meta-data
          android:name="io.fabric.ApiKey"
          android:value="<FABRIC_API_KEY>"
      />
</application>
Krishna Sharma
  • 2,828
  • 1
  • 12
  • 23
0

Well, now that I look at your code it looks like there is definitely a better solution for that than the way I am doing it, but the approach I am using works very well so I will share it anyway (I am using only two build types: DEBUG and RELEASE and no variants, so it is sufficient for me). I am simply not initializing the Crashlytics altogether (in MyApp#onCreate) when BuildConfig.DEBUG == True

public class MyApp extends Application {

    @Override
    public void onCreate() {
        super.onCreate();

        if (!BuildConfig.DEBUG) {
            Fabric.with(this, new Crashlytics());
        }
    }
}

But I am sure somebody else with come up with better solution.

  • This works fine if you only have two build types, tho I would honestly avoid any configuration checking in your app code. Use the build file instead. (I think that's why it's called build.gradle as well, since you can configure your gradle builds) – Zun Aug 15 '18 at 07:12
0

In your app level build.gradle add this :

buildscript {
    repositories {
        maven { url 'https://maven.fabric.io/public' }
    }
    dependencies {
        classpath 'io.fabric.tools:gradle:1.+'
    }
}
apply plugin: 'com.android.application'
apply plugin: 'io.fabric'

dependencies {
    compile('com.crashlytics.sdk.android:crashlytics:KIT_VERSION@aar') {
        transitive = true;
    }
}



android {
    buildTypes {
            release {
                shrinkResources true
                minifyEnabled true
                proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            }
            debug {
                minifyEnabled false
                proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'

            }

        }
    productFlavors {
        production {
            buildConfigField 'boolean', 'IS_FABRIC_DISABLED', 'false'
        }
        fabricOn {
            buildConfigField 'boolean', 'IS_FABRIC_DISABLED', 'false'   
        }
        fabricOff {
            buildConfigField 'boolean', 'IS_FABRIC_DISABLED', 'true'           
        }
    }
}

Add below line in your application class onCreate method:(note: this is in kotlin convert it to java)

val core = CrashlyticsCore.Builder().disabled(BuildConfig.IS_FABRIC_DISABLED).build()
Fabric.with(this, Crashlytics.Builder().core(core).build())

After adding this you will see in left side Build Variants with diffrent option. (here I didn't apply fabric option it shows default option)

enter image description here

piet.t
  • 11,718
  • 21
  • 43
  • 52
Shweta Chauhan
  • 6,739
  • 6
  • 37
  • 57