使用ProGuard的原因NoSuchFieldError为ACRA [英] Using ProGuard causes NoSuchFieldError for ACRA

查看:272
本文介绍了使用ProGuard的原因NoSuchFieldError为ACRA的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用ACRA 4.4.0在我的Andr​​oid应用程序接收来自用户的崩溃报告。我的IDE是ADT生成:v22.2.1-833290。前几天我已经开始使用的ProGuard的应用程序,我会公布关于谷歌播放。当我安装,并开始出口签署的apk,一个NoSuchFieldError occures在ACRA报告使用的字段。我的code是:

I use ACRA 4.4.0 in my Android apps to receive crash reports from users. My IDE is ADT Build: v22.2.1-833290. Few days ago I've started using ProGuard for apps I'm going to publish on Google Play. When I install and start exported signed apk, a NoSuchFieldError occures for fields used in ACRA reports. My code is:

@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公共类org.acra。*给没有影响。正如我在GoogleDocs看到的,可能的原因是Proguard的不正确使用动态引用的字段和方法的工作。优化APK(不ACRA)的作品好。有没有办法解决这个问题? 提前致谢。 迈克尔。

Including "-keep public class org.acra.*" in proguard-project.txt gives no effect. As I can see in GoogleDocs, the possible reason is that the Proguard does not work correctly with dynamically referenced fields and methods. Optimized APK(without ACRA) works good. Is there a way to fix this problem? Thanks in advance. Michael.

推荐答案

您可以尝试配置使用ACRA其DOC在这里: HTTPS ://github.com/ACRA/acra/wiki/Proguard 包括这在你的ProGuard配置文件:

You could try configuring ACRA using its doc here: https://github.com/ACRA/acra/wiki/Proguard include this in your proguard config file:

#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);
}

这篇关于使用ProGuard的原因NoSuchFieldError为ACRA的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆