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);
下面添加行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及更高版本。
我有同样的问题,这是由proguard混淆造成的。
解决方案是将以下定制添加到proguard.cfg文件(取自ACRA wiki页面):
请注意,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);
}
确保你已经添加了清单文件
<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);
}
}
在我的情况下,我缺少@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
)
链接地址: http://www.djcxy.com/p/11331.html