Using ProGuard raises a NoSuchFieldError for ACRA

I use ACRA 4.4.0 in my Android applications to receive crash reports from users. My IDE is ADT Build: v22.2.1-833290. A few days ago, I started using ProGuard for applications that I am going to publish on Google Play. When I install and run the exported signed apk, NoSuchFieldError occurs for the 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); } } 

The inclusion of "-keep public class org.acra. *" In proguard-project.txt has no effect. As I see in GoogleDocs, a possible reason is that Proguard is not working correctly using fields and methods with dynamic binding. Optimized APK (without ACRA) works well. Is there any way to solve this problem? Thanks in advance. Michael.

+7
android acra proguard
source share
1 answer

You can try to configure ACRA using your document here: https://github.com/ACRA/acra/wiki/Proguard include this in your proguard configuration 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); } 
+11
source share

All Articles