8

ACRA 本身因一个奇怪的问题而崩溃:

IllegalStateException: Cannot access ErrorReporter before ACRA#init

我有一个运行良好的 ACRA 4.3.0 应用程序。我将整个应用程序更改为一个库,所以我可以做一些小的变体。我创建了一个新项目,除了清单和指向这个新库的链接之外,它完全是空白的。对于尝试此操作的任何其他人,您必须在 AcraApplication.java 中删除“resToastText = R.string.crash_toast_text”行并在 Acra.init(this); 下方添加新行

ACRA.getConfig().setResToastText(R.string.crash_toast_text);

该项目构建良好,在调试中我已经确认 ACRA.init(this); 在我的主程序代码之前和错误发生之前运行。在主程序中,我们设置了一些自定义数据:

ACRA.getErrorReporter().putCustomData("Orientation", "L");

它会导致崩溃(或者更准确地说,ACRA 本身会导致错误)并且不会生成 ACRA 报告。

任何想法接下来要尝试什么或指向哪里看?可能是 ACRA 与库不兼容,如果是这种情况,我可以将其拉出来以不同的方式处理,但这有点违背了库的目的。


解决方案:不要添加下面的行,而是Acra.init(this);在 init 行之前添加这三行:

ACRAConfiguration config = ACRA.getNewDefaultConfig(this); 
config.setResToastText(R.string.crash_toast_text);
ACRA.setConfig(config);

ACRA.init(this);

请注意,这只适用于 v4.3.0 及更高版本。

4

3 回答 3

1

我有同样的问题,它是由 proguard 混淆引起的。

解决方案是将以下自定义添加到 proguard.cfg 文件(取自 ACRA wiki page here):

请注意, ACRA.init() 应保留在开头:

@Override
  public void onCreate() {
    ACRA.init(this);
    ACRA.getErrorReporter().setReportSender(new MySender());

    super.onCreate();
  } 

proguard.cfg:

#ACRA specifics
# we need line numbers in our stack traces otherwise they are pretty useless
-renamesourcefileattribute SourceFile
-keepattributes SourceFile,LineNumberTable

# ACRA needs "annotations" so add this... 
-keepattributes *Annotation*

# keep this class so that logging will show 'ACRA' and not a obfuscated name like 'a'.
# Note: if you are removing log messages elsewhere in this file then this isn't necessary
-keep class org.acra.ACRA {
    *;
}

# keep this around for some enums that ACRA needs
-keep class org.acra.ReportingInteractionMode {
    *;
}

-keepnames class org.acra.sender.HttpSender$** {
    *;
}

-keepnames class org.acra.ReportField {
    *;
}

# keep this otherwise it is removed by ProGuard
-keep public class org.acra.ErrorReporter
{
    public void addCustomData(java.lang.String,java.lang.String);
    public void putCustomData(java.lang.String,java.lang.String);
    public void removeCustomData(java.lang.String);
}

# keep this otherwise it is removed by ProGuard
-keep public class org.acra.ErrorReporter
{
    public void handleSilentException(java.lang.Throwable);
}
于 2013-05-16T19:26:34.893 回答
1

确保您已在清单文件中添加

<application
    android:name="com.test.MyApp"

并且您有执行以下操作的应用程序类

import org.acra.ACRA;
import org.acra.ReportField;
import org.acra.ReportingInteractionMode;
import org.acra.annotation.ReportsCrashes;

import android.app.Application;

@ReportsCrashes(formKey = "", mailTo = "your_email_address", customReportContent = {
            ReportField.APP_VERSION_CODE, ReportField.APP_VERSION_NAME,
            ReportField.ANDROID_VERSION, ReportField.PHONE_MODEL,
            ReportField.CUSTOM_DATA, ReportField.STACK_TRACE, ReportField.LOGCAT }, mode = ReportingInteractionMode.TOAST, resToastText = R.string.crash_toast_text)
    public class MyApp extends Application
    {
        @Override
        public void onCreate()
        {
            super.onCreate();
            ACRA.init(this);
        }
    }
于 2014-01-28T06:00:12.180 回答
1

在我的情况下,我错过了@ReportCrashes 配置......希望这会奏效

@ReportsCrashes(
    formUri = "uploadurl",
    reportType = HttpSender.Type.JSON,
    httpMethod = HttpSender.Method.POST,
    formUriBasicAuthLogin = "llenigingeneyederrownlys",
    formUriBasicAuthPassword = "1a35b13f9f54271d23a9aed988451182e5b97211",
    formKey = "", // This is required for backward compatibility but not used
    customReportContent = {
            ReportField.APP_VERSION_CODE,
            ReportField.APP_VERSION_NAME,
            ReportField.ANDROID_VERSION,
            ReportField.PACKAGE_NAME,
            ReportField.REPORT_ID,
            ReportField.BUILD,
            ReportField.STACK_TRACE
    },
    mode = ReportingInteractionMode.TOAST,
    resToastText =R.string.msg

)
于 2016-05-17T07:29:53.147 回答