gpt4 book ai didi

android - ACRA 可以用于图书馆项目吗?

转载 作者:塔克拉玛干 更新时间:2023-11-02 18:58:41 25 4
gpt4 key购买 nike

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

IllegalStateException:无法在 ACRA#init 之前访问 ErrorReporter

我有一个运行完美的 ACRA 4.3.0 应用程序。我将整个应用程序更改为一个库,这样我就可以做一些小的改动。我创建了一个新项目,除了 list 和指向这个新库的链接之外,它完全是空白的。对于任何其他尝试此操作的人,在 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("方向", "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 及更高版本。

最佳答案

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

解决方案是将以下自定义添加到 proguard.cfg 文件(取自 ACRA wiki 页面 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);
}

关于android - ACRA 可以用于图书馆项目吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13000611/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com