I have a few models that I want to obfuscate in my code.
I know that I could just ignore the whole model package but I don't want to do that.
I tried a few proguard tweaks and checked all relevant posts to no avail. ORMlite keeps throwing java.lang.RuntimeException: Unable to create application ...App: java.lang.IllegalArgumentException: Foreign field class ....f.p does not have id field
. I checked that the annotation is still there with dex2jar and jd, and it is still there.
I have this proguard configuration (and a lot more that obfuscates other parts):
aggressive stuff :
-mergeinterfacesaggressively
-allowaccessmodification
-optimizationpasses 5
-verbose
-dontskipnonpubliclibraryclasses
-dontpreverify
-optimizations !code/simplification/arithmetic,!field/*,!class/merging/*
keep information needed by various frameworks:
-keepattributes *Annotation*
-keepattributes Signature
-keepattributes EnclosingMethod
ORMLITE related:
-keep class com.j256.**
-keepclassmembers class com.j256.** { *; }
-keep enum com.j256.**
-keepclassmembers enum com.j256.** { *; }
-keep interface com.j256.**
-keepclassmembers interface com.j256.** { *; }
Am I missing something or is this just not possible?
In addition to Vivek Soneja's answer: There is a way to keep entity classes independently from their packages:
It will keep all
DatabaseTable
annotated classes as well as theirDatabaseField
andForeignCollectionField
annotated fieldsAs ORMLite uses reflection to save or retain your data, they want un-obfuscated name of entity (ie classes you are using to save or retain data).
This exception is thrown because ORMLite is trying to find the Entity classes for its tables and its not able to find the classes and members with similar name.
Just Ignore your entity classes from getting obfuscated using following code:
where com.xyz.components is your package for Entity classes.
I hope this helps!