Using ProGuard causes NoSuchFieldError for ACRA

邮差的信 提交于 2020-01-02 01:38:46

问题


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

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.


回答1:


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


来源:https://stackoverflow.com/questions/23340971/using-proguard-causes-nosuchfielderror-for-acra

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!