ACRA ProGuard rules

ACRA - library enabling Android Application to automatically post their crash reports to a report server.

It is targeted to android applications developers to help them get data from their applications when they crash or behave erroneously.

ProGuard rules for ACRA

All unused classes and class members removed in the optimization step. After ProGuard shrinks and obfuscates your code, short names like 'a', 'b', etc. are used as obfuscated names. Add the next rules in ProGuard proguard-rules.pro file.

-optimizationpasses 5
-dontusemixedcaseclassnames
-dontskipnonpubliclibraryclasses
-dontpreverify
-verbose
-optimizations !code/simplification/arithmetic,!field/*,!class/merging/*
-keep public class * extends android.app.Activity
-keep public class * extends android.app.Application
-keep public class * extends android.app.Service
-keep public class * extends android.content.BroadcastReceiver
-keep public class * extends android.content.ContentProvider
-keep public class com.android.vending.licensing.ILicensingService
-keepclasseswithmembernames class * {
    native ;
}
-keepclasseswithmembernames class * {
    public (android.content.Context, android.util.AttributeSet);
}
-keepclasseswithmembernames class * {
    public (android.content.Context, android.util.AttributeSet, int);
}
-keepclassmembers enum * {
    public static **[] values();
    public static ** valueOf(java.lang.String);
}
-keep class * implements android.os.Parcelable {
  public static final android.os.Parcelable$Creator *;
}

Since 4.8.0 ACRA has shipped with it's own proguard.cfg, but if for some reason you want to override ACRA's config then these are the values that ACRA is recommending.

#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 all the ACRA classes
-keep class org.acra.** { *; }

# Don't warn about removed methods from AppCompat
-dontwarn android.support.v4.app.NotificationCompat*

Recommend keep all the ACRA classes so that your Proguard config remains simple. You don't really need to trim or obfuscate the ACRA classes do you? It's not like ACRA is a big library or especially secret.

But if you really feel you need to pare them down as much as possible then use the following:

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

For more information about ACRA please see the website.

Related ProGuard rules

Static Gson ProGuard rules

Popular ProGuard rules