38

I have two build flavors in gradle but for some reason whenever i change the following flag to false i get the titled error message:

ext.enableCrashlytics = false

the error itself complete is below:

Process: com.mobile.myapp.staging, PID: 5439
java.lang.RuntimeException: Unable to create application com.mobile.myapp.UI.myappApplication: io.fabric.sdk.android.services.concurrency.UnmetDependencyException: This app relies on Crashlytics. Please sign up for access at https://fabric.io/sign_up,
install an Android build tool and ask a team member to invite you to this app's organization.
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4710)
at android.app.ActivityThread.-wrap1(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1405)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
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,
install an Android build tool and ask a team member to invite you to this app's organization.
at com.crashlytics.android.core.CrashlyticsCore.onPreExecute(CrashlyticsCore.java:234)
at com.crashlytics.android.core.CrashlyticsCore.onPreExecute(CrashlyticsCore.java:207)
at io.fabric.sdk.android.InitializationTask.onPreExecute(InitializationTask.java:44)
at io.fabric.sdk.android.services.concurrency.AsyncTask.executeOnExecutor(AsyncTask.java:611)
at io.fabric.sdk.android.services.concurrency.PriorityAsyncTask.executeOnExecutor(PriorityAsyncTask.java:43)
at io.fabric.sdk.android.Kit.initialize(Kit.java:69)
at io.fabric.sdk.android.Fabric.initializeKits(Fabric.java:440)
at io.fabric.sdk.android.Fabric.init(Fabric.java:384)
at io.fabric.sdk.android.Fabric.setFabric(Fabric.java:342)
at io.fabric.sdk.android.Fabric.with(Fabric.java:313)
at com.mobile.myapp.UI.base.BaseApplication.setupExceptionHandling(BaseApplication.java:51)
at com.mobile.myapp.UI.myappApplication.onCreate(myappApplication.java:45)
at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1013)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4707)

And this is how I initialize crashlytics in my Application subclass:

Fabric.with(this, new Crashlytics());

what i am trying to do is have control over whether or not a crashlytics can run or not per flavor. lets say i want flavor1 not to run crashlytics i thought i could use that gradle flag and set it to false. am i missing something ?

MD. Khairul Basar
  • 4,976
  • 14
  • 41
  • 59
j2emanue
  • 60,549
  • 65
  • 286
  • 456

7 Answers7

76

Maybe missing apply plugin fabric

I added this line on top of file app/build.gradle resolved my issues!

apply plugin: 'io.fabric'

DaoLQ
  • 988
  • 1
  • 6
  • 13
  • 3
    This is correct! This is for app-level `build.gradle`. – Mike Keskinov Sep 04 '18 at 19:03
  • After writing this line, getting WARNING : `WARNING: API 'variant.getExternalNativeBuildTasks()' is obsolete and has been replaced with 'variant.getExternalNativeBuildProviders()'. It will be removed at the end of 2019.` – Pratik Butani Feb 01 '19 at 06:19
  • @DaoLQ when I add that option everything works well when I build the debug version but on the CI the build fails because it can't find the io.Fabric plugin – 1048576 Feb 06 '19 at 11:37
  • We must add this line apply plugin: 'io.fabric' – Vinod Pattanshetti Jul 22 '19 at 10:39
36

Whenever I set

ext.enableCrashlytics = false

my app crashes with

io.fabric.sdk.android.services.concurrency.UnmetDependencyException

This app relies on Crashlytics. Please sign up for access at https://fabric.io/sign_up, install an Android build tool and ask a team member to invite you to this app's organization.

What seems to work for me is that I have to disable automatic initialization of Crashlytics by adding this line to AndroidManifest.xml

<meta-data android:name="firebase_crashlytics_collection_enabled" android:value="false" />

Then I manually initialize Crashlytics in the onCreate() method of my Application subclass, use BuildConfig.DEBUG to decide whether to disable CrashlyticsCore, and call Fabric.with(). In fact, I no longer set

ext.enableCrashlytics = false

at all. It all seems to work to me.

KGBird
  • 789
  • 10
  • 9
  • 2
    Thanks. Worked for me too. Some related Google documentation: https://firebase.google.com/docs/crashlytics/force-a-crash?authuser=0#enable_debug_mode – albert c braun May 24 '18 at 04:30
  • 2
    Many thanks. Seems like https://docs.fabric.io/android/crashlytics/build-tools.html#disable-crashlytics-for-debug-builds which forces us to add "ext.enableCrashlytics = false" necessarily just confuses people – Valeriy Posvistak Aug 15 '18 at 09:33
29

Addition to answer of Todd Burner

Be carefull with BuildConfig.DEBUG. IDE can auto-import it from

com.crashlytics.android.BuildConfig (= false)

instead of your app config

${app_package}.BuildConfig

UPDATE

Providing an example on the request of j2emanue

    ...
    import com.fiot.ot.BuildConfig             <- should be
    import com.crashlytics.android.BuildConfig <- my IDE automatically imported 

    fun initFabric(context: Context) {
        val core = CrashlyticsCore.Builder().disabled(BuildConfig.DEBUG).build()
        val kit = Crashlytics.Builder().core(core).build()
        Fabric.with(context, kit)
    }

Where com.fiot.ot package name of my app

nuamehas
  • 614
  • 9
  • 14
  • Can you give an example – j2emanue Oct 27 '17 at 13:18
  • anwyay to disable crashlytics per flavor yet ? – j2emanue Oct 30 '17 at 08:19
  • I guess below approach should work (didn't check by myself) `CrashlyticsCore.Builder().disabled(BuildConfig.FLAVOR.equals("myFlavor")).build()` – nuamehas Oct 30 '17 at 11:16
  • 1
    You got it. This is the answer i wanted if you want to post 1. Thanks – j2emanue Oct 30 '17 at 13:03
  • Same as @j2emanue, did not realize that I imported the wrong BuildConfig class. Thank you so much.... – Yajairo87 Oct 31 '17 at 15:15
  • 7
    Where to put this? I set ext.enableCrashlytics = false for debug build and use your code in the app onCreate() method but the app crash before onCreate() was called. Thanks! – Hai nguyen thanh Nov 15 '17 at 01:10
  • To disable in debug mode is not good option. in my case i used two accounts and use manifest variable according to build type. Important point to note. each variant should be signed to make it work – Khizar Hayat Nov 16 '17 at 09:06
  • I've followed the docs from the site: https://docs.fabric.io/android/crashlytics/build-tools.html And still app crashes, this doesn't work for me... any suggestions – Kostadin Georgiev Oct 17 '18 at 14:20
12

Todd from Fabric. You will get this error unless you also disable Fabric at run time.

    // 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);

Check out this link for more details: https://docs.fabric.io/android/crashlytics/build-tools.html#disable-crashlytics-for-debug-builds

Todd Burner
  • 2,202
  • 12
  • 15
  • ok, actually i wanted to disable it per flavor not per debug status. but if nothing else i'll do it this way. – j2emanue Aug 23 '17 at 17:22
  • 8
    Where to put this? I set ext.enableCrashlytics = false for debug build and use your code in the app onCreate() method but the app crash before onCreate() was called. Thanks! – Hai nguyen thanh Nov 15 '17 at 01:09
  • @KGBird shared the right answer which actually works! Sadly, this answer and the way mentioned in the docs doesn't work :( – MiaN KhaLiD May 23 '18 at 10:02
  • @Todd Why is this even NOT INCLUDED on the official documentation? There's a ton of implementation you can found online how to do this very core task. Please be consistent with your code – mr5 Jun 20 '18 at 02:20
  • 2
    @Todd: This is not working. I followed the same instructions from fabric but it doesn't work. – sam_k Jul 18 '18 at 04:06
  • Looks nice, but not working. That's great actually simple documentation is not working, see the irony :)) – Farid Jan 25 '19 at 07:26
9

Make sure you add in

app.gradle

apply plugin: 'io.fabric'

I also have

classpath 'io.fabric.tools:gradle:1.26.1'

in the

project gradle dependencies

and add the Crashlytics api in the strings, signup in the Crashlytics Site

Joseph Wambura
  • 2,732
  • 2
  • 21
  • 24
6

For Xamarin Android (Fabric is Deprecated - EOL)

You need to have the following not to receive the above error:

  1. Include the NuGet packages:
    • Xamarin.Android.Crashlytics [by Microsoft]
    • Xamarin.Android.Crashlytics.Core [by Microsoft]
    • Xamarin.Android.Crashlytics.Beta [by Microsoft]
    • Xamarin.Android.Crashlytics.Answers [by Microsoft]
  2. Add this line in your AndroidManifest.xml file within <application>:

    <meta-data android:name="io.fabric.ApiKey" android:value="<FABRIC_API_KEY>" />

  3. Add this line in Resources/values/Strings.xml resource file:

    <string name="com.crashlytics.android.build_id">15</string>

  4. Add this line in MainApplication.cs or YourActivity.cs in OnCreate():

    Fabric.Fabric.With(this, new Crashlytics.Crashlytics());

Your app should build and run past the initialization line without any issues. Only problem I have with it is the fact that there is one more place you need to update the Build version of your app everytime your release.


EDIT :

As far as I'm experiencing, the one value is required but not used at all. You do not actually have to increase the build number in Strings.xml, it picks up the build number from the app automatically, so you should be fine just to leave the value at: <string name="com.crashlytics.android.build_id">1</string>

If you experience it differently for Xamarin, please comment below.

Pierre
  • 8,397
  • 4
  • 64
  • 80
1

In My case this got worked.

so, this is the top level project build.gradle

buildscript {
    repositories {
        jcenter()
        maven { url 'https://maven.fabric.io/public' }
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:1.2.3'
        classpath 'io.fabric.tools:gradle:1.+'
    }
}
apply plugin: 'java'
allprojects {
    repositories {
        jcenter()
        maven { url 'https://maven.fabric.io/public' }
    }
}

and this is the build.gradle for app module

apply plugin: 'com.android.application'
apply plugin: 'io.fabric'

android {
compileSdkVersion 22
buildToolsVersion "22.0.1"

defaultConfig {
    applicationId "your application package name"
    minSdkVersion 10
    targetSdkVersion 22
}

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

dependencies {
compile 'com.google.code.gson:gson:2.3'
compile 'com.android.support:support-v4:22.0.0'
testCompile 'junit:junit:4.12'
testCompile "org.mockito:mockito-core:1.9.5"
compile('com.crashlytics.sdk.android:crashlytics:2.5.2@aar') {
    transitive = true;
}
}

and at last "clean build" and all was set for me.