Reputation: 647
I have an sbt Scala project:
Subproject lib contains some classes with @SerialVersionUID, such as in:
@SerialVersionUID(10L) class MyStuff extends Serializable { ... }
Project app is an Android application (uses android-sdk-plugin), it has lib as its dependency
I have a file, into which I serialized a number of MyStaff objects using local JVM on my dev machine (1.7.0_75)
When I try to deserialize this file using the same JVM, all works fine
When I try to deserialize this file on Android, using exactly the same code, I get the following error message:
java.io.InvalidClassException: com.example.MyStuff; Incompatible class (SUID): com.example.MyStuff: static final long serialVersionUID =10L; but expected com.example.MyStuff: static final long serialVersionUID =-7513795898815927590L;
So, looks like my serialVersionUID was lost while in transition to Android. Any ideas why? Some proguard settings? Something funky with Dalvik? Me being somehow stupid (most likely :) )
Upvotes: 2
Views: 337
Reputation: 647
Looks like I can answer my own question. After some research I figured, that
A SO discussion: Serialization / Deserialization & Proguard
And a blog post with concrete details and a workaround:
http://littlepancake.com/2011/09/proguard-and-serialized-java-objects/
It boils down to the fact, that you need to guard serialization-related stuff from overzealous Proguard elimination, like this:
-keepclassmembers class com.example.full.class.Name {
static final long serialVersionUID;
java.lang.Object writeReplace();
java.lang.Object readResolve();
private static final java.io.ObjectStreamField[] serialPersistentFields;
}
Note, Proguard understands wildcards as well :)
Upvotes: 1