I was writing a piece of code in Scala, which was supposed to de-serialize some Java object, previously serialized elsewhere. However, I kept seeing exceptions like these:

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;

In my code I did have classes declared with the @SerialVersionUID attribute. The same code worked fine on my development machine. So it looked like it got lost from the class bytecode by the time that I ran it on Android. I initially suspected, that there could be a discrepancy in serialization representation between Dalvik (Android's JVM) and the classic JVM released by Sun, now Oracle. However, after some research, I reached a conclusion that it was overzealous proguard tool which simply stripped @SerialVersionUID from my classes. I fixed the issue using the following config:

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

and now everything works fine.

Tags: None
Categories: None |

0 comments have been posted.

Your email: we will send you a confirmation link to this address to confirm your identity and to prevent robot posting
Get in touch
»...«
Follow updates

Join our social networks and RSS feed to keep up to date with latest news and publications