Android How to initialize Crashlytics in Fabric.io?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/26535438/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 11:44:43  来源:igfitidea点击:

How to initialize Crashlytics in Fabric.io?

androidcrashlyticstwitter-fabric

提问by Nidhi Shah

Looking for some help. I just upgraded my android app to fabric and now the app gives an error on this line:

Looking for some help. I just upgraded my android app to fabric and now the app gives an error on this line:

Crashlytics.start(getApplicationContext());

Crashlytics.start(getApplicationContext());

Gradle: error: cannot find symbol method start(Context)

Gradle: error: cannot find symbol method start(Context)

I tried commenting out that line, but then the crashes are not getting logged. How do I initialize Crashlytics in the new fabric framework? Am I missing something?

I tried commenting out that line, but then the crashes are not getting logged. How do I initialize Crashlytics in the new fabric framework? Am I missing something?

Thanks in advance for your help.

Thanks in advance for your help.

回答by Cipriani

Since Crashlytics is now part of Fabric the initialization process has changed, but is still simple. Instead of using Crashlytics.start()you should now use, but in the Application creation:

Since Crashlytics is now part of Fabric the initialization process has changed, but is still simple. Instead of using Crashlytics.start()you should now use, but in the Application creation:

public class App extends Application {

    ...

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

    ...

}

For a more richer example, see how Cannonball canonical sample app is doing:

For a more richer example, see how Cannonball canonical sample app is doing:

public class App extends Application {

    ...

    private TwitterAuthConfig authConfig;

    ...

    @Override
    public void onCreate() {
        super.onCreate();
        authConfig = new TwitterAuthConfig(BuildConfig.CONSUMER_KEY, BuildConfig.CONSUMER_SECRET);
        Fabric.with(this, new Crashlytics(), new Twitter(authConfig), new MoPub());
    }

    ...

}

This code is available at: https://github.com/twitterdev/cannonball-android/blob/master/app/src/main/java/io/fabric/samples/cannonball/App.java#L96-L98

This code is available at: https://github.com/twitterdev/cannonball-android/blob/master/app/src/main/java/io/fabric/samples/cannonball/App.java#L96-L98

回答by Andrii Kovalchuk

In latest version init is done automatically by ContentProvider https://firebase.google.com/docs/crashlytics/upgrade-sdk?platform=android

In latest version init is done automatically by ContentProvider https://firebase.google.com/docs/crashlytics/upgrade-sdk?platform=android

 import com.google.firebase.crashlytics.FirebaseCrashlytics

// ...

// Explicit initialization of Crashlytics is no longer required.

// OPTIONAL: If crash reporting has been explicitly disabled previously, add:
FirebaseCrashlytics.getInstance().setCrashlyticsCollectionEnabled(true)