Crashlytics crash with proguard

2019-05-27 05:08发布

问题:

I did everything that fabric ask in their documentation:

-renamesourcefileattribute SourceFile
-keepattributes *Annotation*
-keepattributes SourceFile,LineNumberTable
-keep public class * extends java.lang.Exception
-keep class com.crashlytics.** { *; }
-dontwarn com.crashlytics.**

But still got this error:

E/Answers: Failed to submit events task java.util.concurrent.RejectedExecutionException: Task java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask@d2d2a84 rejected from java.util.concurrent.ScheduledThreadPoolExecutor@6b49897[Shutting down, pool size = 1, active threads = 0, queued tasks = 1, completed tasks = 5] at java.util.concurrent.ThreadPoolExecutor$AbortPolicy.rejectedExecution(ThreadPoolExecutor.java:2014) at java.util.concurrent.ThreadPoolExecutor.reject(ThreadPoolExecutor.java:794) at java.util.concurrent.ScheduledThreadPoolExecutor.delayedExecute(ScheduledThreadPoolExecutor.java:302) at java.util.concurrent.ScheduledThreadPoolExecutor.schedule(ScheduledThreadPoolExecutor.java:527) at java.util.concurrent.ScheduledThreadPoolExecutor.submit(ScheduledThreadPoolExecutor.java:626) at java.util.concurrent.Executors$DelegatedExecutorService.submit(Executors.java:594) at com.crashlytics.android.answers.AnswersEventsHandler.executeAsync(SourceFile:182) at com.crashlytics.android.answers.AnswersEventsHandler.processEvent(SourceFile:168) at com.crashlytics.android.answers.AnswersEventsHandler.processEventAsync(SourceFile:44) at com.crashlytics.android.answers.SessionAnalyticsManager.onLifecycle(SourceFile:128) at com.crashlytics.android.answers.AnswersLifecycleCallbacks.onActivityStopped(SourceFile:43) at io.fabric.sdk.android.c.onActivityStopped(SourceFile:126) at android.app.Application.dispatchActivityStopped(Application.java:232) at android.app.Activity.onStop(Activity.java:1620) at android.support.v4.app.FragmentActivity.onStop(SourceFile:616) at android.support.v7.app.AppCompatActivity.onStop(SourceFile:172) at android.app.Instrumentation.callActivityOnStop(Instrumentation.java:1279) at android.app.Activity.performStop(Activity.java:6395) at android.app.ActivityThread.performDestroyActivity(ActivityThread.java:3824) at android.app.ActivityThread.handleDestroyActivity(ActivityThread.java:3883) at android.app.ActivityThread.-wrap5(ActivityThread.java) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1417) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:148) at android.app.ActivityThread.main(ActivityThread.java:5461) 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)

In addition: build gradle:

dependencies {
    // The Fabric Gradle plugin uses an open ended version to react
    // quickly to Android tooling updates
    classpath 'io.fabric.tools:gradle:1.21.7'
}
compile('com.crashlytics.sdk.android:crashlytics:2.6.2@aar') {
    transitive = true;
}
compile('com.crashlytics.sdk.android:answers:1.3.8@aar') {
    transitive = true;
}
apply plugin: 'io.fabric'

buildTypes {
    release {
        signingConfig signingConfigs.release
        minifyEnabled true
        shrinkResources true
        proguardFiles 'proguard-rules.pro'
    }

My activity:

public class BaseActivity extends AppCompatActivity{

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Thread.setDefaultUncaughtExceptionHandler(new ExceptionHandler(this));
        Fabric.with(this, new Answers(), new Crashlytics.Builder().core(new CrashlyticsCore.Builder().disabled(BuildConfig.DEBUG).build()).build());
    }
}

Opened issue in Twitter forum too:
https://twittercommunity.com/t/e-answers-failed-to-submit-events-task/72921/3

回答1:

Finaly i found my problem. I didn't see it before but, Thread.UncaughtExceptionHandler was the problem.
It should be after the initialization of fabric crashlytics while it was one line before.

I solved it by this code:

   @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        // Order is important!
        // First, start Crashlytics
        Fabric.with(this, new Answers(), new Crashlytics.Builder().core(new CrashlyticsCore.Builder().disabled(BuildConfig.DEBUG).build()).build());

        // Second, set custom UncaughtExceptionHandler
        Thread.UncaughtExceptionHandler mDefaultUEH = Thread.getDefaultUncaughtExceptionHandler();
        ExceptionHandler exceptionHandler = new ExceptionHandler(this, mDefaultUEH);
        Thread.setDefaultUncaughtExceptionHandler(exceptionHandler);
}