Proguard Obfuscation Enum Issue - android

I have following Enum class in my Java package
public enum UIType {
NATIVE,WEB;
}
I have applied following proguard config to keep this enum class
-keepclassmembers enum * {
public static **[] values();
public static ** valueOf(java.lang.String);
}
-keep public enum android.ui.UIType {
public static **[] values();
public static ** valueOf(java.lang.String);
}
But when I offuscate my jar file,proguard keeps the UIType enum class but removes both NATIVE,WEB values.
In my obfuscated jar my Enum class looks as follows.
public enum UIType {
}
As seen above NATIVE,WEB values are removed by proguard :(.It is causing issue in my application since it is not finding those values.
Can somebody please guide me here what I am doing wrong.
Thanks

As I understand, you ask it to keep the methods values() and valueOf(), but not the values themselves.
Try
-keep public class com.ggg.xxx.Yyy { *; }

Related

The rule matches no class members for enum in proguard

I have enum decalare as
enum class PARTY {
START, STOP
}
And in proguard I have added
-keep public enum com.interface.PartyChart$PARTY{
<fields>;
public static **[] values();
public static ** valueOf(java.lang.String);
}
I get this message in proguard file
The rule matches no class members

Dexguard always crash with enum

I'm using DexGuard Enterprise for my apps. And I find that whenever I use a library that have ENUM in it (for eg: ZXing), DexGuard did something to the code that my app would crash with errors like
java.lang.AssertionError: impossible
at java.lang.Enum$1.create(Enum.java:49)
at java.lang.Enum$1.create(Enum.java:35)
at libcore.util.BasicLruCache.get(BasicLruCache.java:54)
at java.lang.Enum.getSharedConstants(Enum.java:211)
at java.lang.Enum.valueOf(Enum.java:191)
at com.google.zxing.BarcodeFormat.valueOf(:24)
I tried options such as these (as I found them on other questions), but not working
-keep enum com.google.zxing.** {
*;
}
what seems to be the problem? How could I fix it? It's bugging me for weeks now.
Try to add the following in your proguard file.
# For enumeration classes, see http://proguard.sourceforge.net/manual/examples.html#enumerations
-keepclassmembers enum * {
public static **[] values();
public static ** valueOf(java.lang.String);
}
You can add allowoptimization also
-keepclassmembers,allowoptimization enum * {
public static **[] values();
public static ** valueOf(java.lang.String);
}
https://www.guardsquare.com/en/products/proguard/manual/examples#enumerations

android - how to keep enum from proguard

In my proguard, I have the following to keep public enums from being obfuscated.
-keepclassmembers enum * {
public static **[] values();
public static ** valueOf(java.lang.String);
}
My question is, does this also keep the public enum Currency in a class like this?
public class Foo {
public enum **Currency** {PENNY, NICKLE, DIME, QUARTER};
...
}
If not, what do I have to add separately?
Adding the following doesn't seem to help.
-keepattributes InnerClasses
Any advice? Thanks
You could try
-keep public enum com.stuff.TheEnclosingClass$** {
**[] $VALUES;
public *;
}
As shown on this answer Proguard won't keep a class member's enums
Just don't forget to put
-keepattributes InnerClasses
Can you try to tell proguard to keep the specific class:
-keep class com.xxx.Foo { *; }
The option -keepclassmembers only keeps the class members; in this case the methods values() and valueOf(String) of all enum classes. The wild card * also matches internal classes.
If you for some reason want to preserve the inner class with its original name, you can specify:
-keep class somepackage.Foo$Currency
That should only be necessary if your application accesses the class through reflection.
If you want to safe enum names and all fields, methods for it:
-keep enum * { *; }

card.io strings do not change with proguard

I have a problem with obfuscation on card.io.
I'm changing the strings on strings.xml with the tags given on card.io official page and while I'm debugging, the app uses the changed strings. But when i export signed apk with proguard, the app uses its own strings. Could you help me? What am I missing?
This is my proguard.cfg content: (I use the sample app's proguard 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 * extends android.app.backup.BackupAgentHelper
-keep public class * extends android.preference.Preference
-keepclasseswithmembernames class * {
native <methods>;
}
-keepclasseswithmembers class * {
public <init>(android.content.Context, android.util.AttributeSet);
}
-keepclasseswithmembers class * {
public <init>(android.content.Context, android.util.AttributeSet, int);
}
-keepclassmembers class * extends android.app.Activity {
public void *(android.view.View);
}
-keepclassmembers enum * {
public static **[] values();
public static ** valueOf(java.lang.String);
}
-keep class * implements android.os.Parcelable {
public static final android.os.Parcelable$Creator *;
}
-keep class io.card.**
-keepclassmembers class io.card.** {
*;
}
## Good practice so that you don't end up logging sensitive info.
# Remove debug, verbose, and info Log calls
-assumenosideeffects class android.util.Log {
public static *** d(...);
public static *** v(...);
public static *** i(...);
## Uncomment to remove warnings and errors as well
# public static *** w(...);
# public static *** e(...);
}
Jeff from card.io here.
card.io no longer supports the strings.xml file as of version 3.1.0+, because the SDK provides translations. Are you using the latest version?
If not, please download the latest SDK. You can either rely on the device language settings to automatically bring up the correct localizations, or force a locale with CardIOActivity.EXTRA_LANGUAGE_OR_LOCALE (see javadocs).
To add to Jeff's response, if there's a problem with a translation, we'd like to fix it! Please file bugs here.
I've also updated the example app to remove the strings examples. Thanks for letting us know that it was out of date.

Getting java.lang ExceptionInInitializerError when initializing ACRA

I integrated ACRA to my application to get crash reports from my app in beta stadium so I'm able to fix bugs, find errors in code, etc. If I run this on the emulator everything works fine and ACRA is up and running, but if I export a signed package of my application with Android Tools I get an ExceptionInInitializeError and the application is force closed on the device. If I catch this Error and proceed without ACRA the app itself runs like a charm...
has anybody here got the same issue with ACRA? could it be that it has something to do with ProGuard? I followed the ProGuard how to on ACRA homepage but perhaps I'm missing something on this?
here's what my proguard.cfg looks like:
-injars 'C:\Workspaces\motodevWs\gp2012\bin\classes'
-injars 'C:\Workspaces\motodevWs\gp2012\libs'
-outjars 'C:\Workspaces\motodevWs\gp2012\bin\classes-processed.jar'
-libraryjars 'C:\android\android-sdk\platforms\android-7\android.jar'
-libraryjars 'C:\android\android-sdk\add-ons\addon_google_apis_google_inc_7 \libs\maps.jar'
-optimizations !code/simplification/arithmetic
-allowaccessmodification
-repackageclasses ''
-keepattributes *Annotation*,SourceFile,LineNumberTable,*Annotation*
-renamesourcefileattribute SourceFile
-dontpreverify
-dontwarn java.awt.**,javax.security.**,java.beans.**,com.sun.**
-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 * extends android.view.View {
public <init>(android.content.Context);
public <init>(android.content.Context,android.util.AttributeSet);
public <init>(android.content.Context,android.util.AttributeSet,int);
public void set*(...);
}
-keepclasseswithmembers class * {
public <init>(android.content.Context,android.util.AttributeSet);
}
-keepclasseswithmembers class * {
public <init>(android.content.Context,android.util.AttributeSet,int);
}
-keepclassmembers class * extends android.os.Parcelable {
static android.os.Parcelable$Creator CREATOR;
}
-keepclassmembers class **.R$* {
public static <fields>;
}
# 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 {
<fields>;
<methods>;
}
# keep this around for some enums that ACRA needs
-keep class org.acra.ReportingInteractionMode {
<fields>;
<methods>;
}
# keep this otherwise it is removed by ProGuard
-keep public class org.acra.ErrorReporter {
public void addCustomData(java.lang.String,java.lang.String);
}
# keep this otherwise it is removed by ProGuard
-keep public class org.acra.ErrorReporter {
public org.acra.ErrorReporter$ReportsSenderWorker handleSilentException(java.lang.Throwable);
}
PROBLEM SOLVED!
After some effort on research and rethinking my problem I found the solution to the problem and it was indeed in my proguard.cfg file where I missed something!
somehow I managed not to keep enums, now I added
-keepclassmembers enum * {
public static **[] values();
public static ** valueOf(java.lang.String);
}
to my proguard.cfg and everything is working perfectly!!
So, to close this question with the answer I found myself, here is what I did to resolve this particular problem :) (taken from my question post):
After some effort on research and rethinking my problem I found the solution to the problem and it was indeed in my proguard.cfg file where I missed something!
somehow I managed not to keep enums, now I added
-keepclassmembers enum * {
public static **[] values();
public static ** valueOf(java.lang.String);
}
to my proguard.cfg and everything is working perfectly!!
THere is now a wiki concerning using ACRA with ProGuard
https://github.com/ACRA/acra/wiki/Proguard

Categories

Resources