Crashlytics与proguard崩溃

时间:2016-08-26 10:27:13

标签: gradle proguard crashlytics android-proguard twitter-fabric

我做了面料在文档中提出的所有要求:

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

但仍然有这个错误:

  

电子邮件/答案:无法提交事件任务                                                                           java.util.concurrent.RejectedExecutionException:任务   java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask@d2d2a84   被拒绝了   java.util.concurrent.ScheduledThreadPoolExecutor@6b49897 [关闭   down,pool size = 1,活动线程= 0,排队任务= 1,完成   任务= 5]                                                                               在   java.util.concurrent.ThreadPoolExecutor中的$ AbortPolicy.rejectedExecution(ThreadPoolExecutor.java:2014)                                                                               在   java.util.concurrent.ThreadPoolExecutor.reject(ThreadPoolExecutor.java:794)                                                                               在   java.util.concurrent.ScheduledThreadPoolExecutor.delayedExecute(ScheduledThreadPoolExecutor.java:302)                                                                               在   java.util.concurrent.ScheduledThreadPoolExecutor.schedule(ScheduledThreadPoolExecutor.java:527)                                                                               在   java.util.concurrent.ScheduledThreadPoolExecutor.submit(ScheduledThreadPoolExecutor.java:626)                                                                               在   java.util.concurrent.Executors $ DelegatedExecutorService.submit(Executors.java:594)                                                                               在   com.crashlytics.android.answers.AnswersEventsHandler.executeAsync(的SourceFile:182)                                                                               在   com.crashlytics.android.answers.AnswersEventsHandler.processEvent(的SourceFile:168)                                                                               在   com.crashlytics.android.answers.AnswersEventsHandler.processEventAsync(的SourceFile:44)                                                                               在   com.crashlytics.android.answers.SessionAnalyticsManager.onLifecycle(的SourceFile:128)                                                                               在   com.crashlytics.android.answers.AnswersLifecycleCallbacks.onActivityStopped(的SourceFile:43)                                                                               at io.fabric.sdk.android.c.onActivityStopped(SourceFile:126)                                                                               在   android.app.Application.dispatchActivityStopped(Application.java:232)                                                                               在android.app.Activity.onStop(Activity.java:1620)                                                                               在android.support.v4.app.FragmentActivity.onStop(SourceFile:616)                                                                               在android.support.v7.app.AppCompatActivity.onStop(SourceFile:172)                                                                               在   android.app.Instrumentation.callActivityOnStop(Instrumentation.java:1279)                                                                               在android.app.Activity.performStop(Activity.java:6395)                                                                               在   android.app.ActivityThread.performDestroyActivity(ActivityThread.java:3824)                                                                               在   android.app.ActivityThread.handleDestroyActivity(ActivityThread.java:3883)                                                                               在android.app.ActivityThread.-wrap5(ActivityThread.java)                                                                               在   android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1417)                                                                               在android.os.Handler.dispatchMessage(Handler.java:102)                                                                               在android.os.Looper.loop(Looper.java:148)                                                                               在android.app.ActivityThread.main(ActivityThread.java:5461)                                                                               at java.lang.reflect.Method.invoke(Native Method)                                                                               在   com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:726)                                                                               在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)

另外: 建立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'
    }

我的活动:

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());
    }
}

Twitter论坛也开启了问题:
https://twittercommunity.com/t/e-answers-failed-to-submit-events-task/72921/3

1 个答案:

答案 0 :(得分:1)

最后我发现了我的问题。我之前没有看到它,但Thread.UncaughtExceptionHandler是问题所在 它应该是在结构崩溃的初始化之后,而它之前是一行。

我用这段代码解决了它:

   @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);
}