Why is Fabric not initialized? java.lang.IllegalStateException: Must Initialize Fabric before using singleton()

天大地大妈咪最大 提交于 2019-12-03 22:06:05

You need to initialize Crashlytics in your application's onCreate

import android.app.Application;

import com.crashlytics.android.Crashlytics;

import io.fabric.sdk.android.Fabric;

public class TestApplication extends Application {
    @Override
    public void onCreate() {
        super.onCreate();
        Fabric.with(this, new Crashlytics());
    }
}

In my case, The below checks helped to get rid of the error.

If you find code like below in your manifest, set it to true or remove it since it's true by default.

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

Also incase if the value is being pulled in from your build.gradle, check which buildType its in and consider not invoking any Crashlytics functions under that buildType.

Example: build.gradle

android{

    ...

   buildTypes {
        debug{
            manifestPlaceholders = [enableCrashReporting:"false"]
        }
        release {
            manifestPlaceholders = [enableCrashReporting:"true"]
        }
   }
}

In this case you should have your Crashlytics calls wrapped like this -

if(!BuildConfig.DEBUG){
   ...
   Crashlytics.setUserIdentifier(...)
   ...
}

When you are using Firebase Crashlytics, you don't need to do any Fabric initialization. Everything is done automatically.

But if you want to do any custom logging, via (for example) Crashlytics.log("Custom log"), you need to have FirebaseCrashlytics enabled in your manifest. Check the manifest if you have something like that:

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

${crashlyticsEnabled} can be set to true or false or via you app level build.gradle. This is typically used to disable Firebase Crashlytics when you are debugging the app.

If you used android:process, then automatic initialization wouldn't work because it works by using a content provider in your manifest. In that case, you'll have to manually initialize Crashlytics.

If you migrated from Fabric.io to Firebase, there must be some lines you need to DELETE from AndroidManifest.xml

        <!-- Fabric.io Analytics key -->
        <meta-data
            android:name="io.fabric.ApiKey"
            android:value="49yy995568140ee22uio128e00450bd99603fd43" />

With those lines, the Crashlytics plugin can NOT be initialized correctly by Firebase.

This error had me beat on an Ionic 4 build. I have installed the Cordova firebaseX module, and this error occurred.

From reading the debug log I managed to see that the firebase crashlytics collection was missing a bool. In the androidmanifest I found this line and simply changed the value to a bool for a hot fix. I put in 'true' - and the error is gone.

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

So for anyone out there was this error on Ionic platform. Look in the androidmanifest file for the above meta line.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!