我在 Android 应用程序中使用 ACRA 4.4.0 来接收用户的崩溃报告。我的 IDE 是 ADT 版本:v22.2.1-833290。几天前,我开始对要在 Google Play 上发布的应用程序使用 ProGuard。当我安装并启动导出的签名 apk 时,ACRA 报告中使用的字段出现 NoSuchFieldError。我的代码是:
@ReportsCrashes(formKey = <my_key>,
mailTo = <my_email>,
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 MyApplication extends Application {
@Override
public void onCreate() {
super.onCreate();
ACRA.init(this);
}
}
在 proguard-project.txt 中包含“-keep public class org.acra.*”没有任何效果。正如我在 GoogleDocs 中看到的,可能的原因是 Proguard 无法正确使用动态引用的字段和方法。优化的 APK(不含 ACRA)效果很好。有办法解决这个问题吗?
提前致谢。
迈克尔.
您可以尝试使用此处的文档配置 ACRA:https://github.com/ACRA/acra/wiki/Proguard https://github.com/ACRA/acra/wiki/Proguard将其包含在您的 proguard 配置文件中:
#ACRA specifics
# Restore some Source file names and restore approximate line numbers in the stack traces,
# otherwise the stack traces are pretty useless
-keepattributes SourceFile,LineNumberTable
# ACRA needs "annotations" so add this...
# Note: This may already be defined in the default "proguard-android-optimize.txt"
# file in the SDK. If it is, then you don't need to duplicate it. See your
# "project.properties" file to get the path to the default "proguard-android-optimize.txt".
-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);
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)