Fra*_*ank 8 android init illegalstateexception acra
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);
Run Code Online (Sandbox Code Playgroud)
请注意,这仅适用于v4.3.0及更高版本.
我遇到了同样的问题,这是由 proguard 混淆引起的。
解决方案是将以下自定义添加到 proguard.cfg 文件(取自 ACRA wiki 页面此处):
请注意,ACRA.init() 应保留在开头:
@Override
public void onCreate() {
ACRA.init(this);
ACRA.getErrorReporter().setReportSender(new MySender());
super.onCreate();
}
Run Code Online (Sandbox Code Playgroud)
混淆器.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);
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1746 次 |
| 最近记录: |