The rule matches no class members for enum in proguard - android

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

Related

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 - proguard ignores -keep on Swig methods

I'm using proguard to obfuscate a (SDK) jar file I've created.
The SDK contains a Java Service, a statically compiled C++ lib and a SWIG (ver 2) interface via which the Service and the lib communicates.
I've added relevant '-keep' and '-keepclasseswithmembernames,includedescriptorclasses' statements to the configuration file.
But one file keeps getting (partially) obfuscated.
The first part of the proguard config looks like this (all collected from the net):
-libraryjars '/Library/DevTools/adt-bundle-mac-x86_64-20140702/sdk/platforms/android-21/android.jar'
-libraryjars 'libs/android-support-v4.jar'
-libraryjars "libs/armeabi-v7a/libnativesdk.so"
-dontskipnonpubliclibraryclasses
-injars bin/mysdklib.jar
-verbose
-dontshrink
-dontoptimize
-dontusemixedcaseclassnames
-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 *;
}
My specific classes addition looks like this:
-keepclasseswithmembernames,includedescriptorclasses class com.company.MySdkIfJNI{
private final static native void swig_module_init();
public static *;
public final static native <methods>;
}
-keepclasseswithmembernames,includedescriptorclasses class com.company.MySdkWrapper{
public *;
}
-keep class com.company.IntWrapper
-keep class com.company.StatisticsParcel{
public *;
}
-keep class com.company.JNILibCallbacks
All the classes I keep works fine. The problem is with the 'MySdkIfJNI' class.
This is an Swig (http://www.swig.org/) auto-generated interface between the native lib and the Java service.
I tried various configurations in order to keep this class as is but proguard keeps obfuscating it.
I tried '-keep' , '-keepclasseswithmembernames,includedescriptorclasses', '-keepclasseswithmembernames'
-keepclasseswithmembernames,includedescriptorclasses class com.company.MySdkIfJNI{
private final static native void swig_module_init();
public static *;
public final static native <methods>;
*;
}
both with arguments and without arguments
But after proguard finishes (without any errors / warnings) I find out that only part of the methods has been obfuscated.
The native methods are kept, such as:
public final static native void JniMYSdkClient_setLogLevel(long jarg1, JniMYSdkClient jarg1_, int jarg2);
public final static native void delete_JniMYSdkClient(long jarg1);
But all the Java methods that starts with SwigDirector are obfuscated, such as:
public static void SwigDirector_JNIMyCallbacks_onEvent(JNIMyCallbacks self, int accountId, int eventId, String sessionId, String msg) {
self.onEvent(accountId, eventId, sessionId, msg);
}
This obfuscation causes the Native swig interface to fail finding this callback methods and my lib crashes.
Any ideas of how can I keep this specific class AS-IS ?
Thanks in advance,
Or Pol.
Well, I didn't find any solution to the particular SWIG methods but since the SWIG wrapping code is already really messy I have decided it doesn't have to be obfuscated with Proguard.
I moved the SWIG interface to an external JAR file and imported it as '-libraryjars'
Now the native layer finds this methods and everything works perfect.
Thanks anyway!
Best regards,
Or.
Swig callbacks need to be keep from obfuscation.
First try to keep all generated java files by swig and compile and see. Crash will fix. Like below
-keep com.custom.project** { *; }
-dontwarn com.custom.project**
Next maximize your files for obfuscation.
Hope it helps.

Proguard Obfuscation Enum Issue

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 { *; }

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.

Categories

Resources