I am using simplexml in my android project, and everything works fine until I obfuscate the code. Then, errors start pouring in.
Part of the XML is as follows:
Try adding this to your proguard file:
-keep public class org.simpleframework.** { *; }
-keep class org.simpleframework.xml.** { *; }
-keep class org.simpleframework.xml.core.** { *; }
-keep class org.simpleframework.xml.util.** { *; }
-keepattributes ElementList, Root
-keepclassmembers class * {
@org.simpleframework.xml.* *;
}
This fixed it for me.
This exact addition to the proguard file worked for me:
-dontwarn javax.xml.stream.**
-keep public class org.simpleframework.** { *; }
-keep class org.simpleframework.xml.** { *; }
-keep class org.simpleframework.xml.core.** { *; }
-keep class org.simpleframework.xml.util.** { *; }
-keepattributes ElementList, Root
-keepclassmembers class * {
@org.simpleframework.xml.* *;
}
The problems when you use the SimpleXML library and obfuscate the code are the followings:
You have to keep the "Annotations" and "Signatures" of your entities
@Attribute(name = "retcode", required = true) private String _retcode;
You have to keep the SimpleXML Library
The proguard.cfg file may to be something like this:
# The following line may be different
-libraryjars <java.home>/lib/rt.jar(java/**,javax/**)
-optimizationpasses 5
-dontusemixedcaseclassnames
-dontskipnonpubliclibraryclasses
-dontpreverify
-verbose
# (3)Not remove unused code
-dontshrink
-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
-keep public class com.android.vending.licensing.ILicensingService
# (2)Simple XML
-keep public class org.simpleframework.**{ *; }
-keep class org.simpleframework.xml.**{ *; }
-keep class org.simpleframework.xml.core.**{ *; }
-keep class org.simpleframework.xml.util.**{ *; }
# (1)Annotations and signatures
-keepattributes *Annotation*
-keepattributes Signature
-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 *;
}
I use it in my own project and it works ;)
Right click your project in eclipse. Go to android -> run Lint.
Lint has the ability to check for proguard misconfigurations and may pick up, and explain your error.
I kept getting the following errors:
can't find referenced class javax.xml.stream.XMLEventReader
can't find referenced class javax.xml.stream.events.XMLEvent
This is because these are part of the Java runtime (rt.jar) but not part of the Android runtime (android.jar), so ProGuard warns that something might be broken. This isn't actually a problem, so we can do the following:
-dontwarn javax.xml.stream.events.**
Source
Combined with the answer of zmicer, I get the following
-dontwarn javax.xml.stream.events.**
-keep public class org.simpleframework.** { *; }
-keep class org.simpleframework.xml.** { *; }
-keep class org.simpleframework.xml.core.** { *; }
-keep class org.simpleframework.xml.util.** { *; }
-keepattributes ElementList, Root
-keepclassmembers class * {
@org.simpleframework.xml.* *;
}
Use the official one from the project Subversion repository.
https://simple.svn.sourceforge.net/svnroot/simple/trunk/download/stream/proguard.pro