ClassNotFoundException when loading .bones with obfuscated code.

Started by kiffa, September 17, 2012, 11:07:54 AM

Previous topic - Next topic

kiffa

I use android-proguard to Obfuscate my code, and ClassNotFoundException happened when  loading .bones. All are ok before obfuscated.

Codes:
//loading .ser, all are ok
obj = Loader.loadSerializedObject(in);

//loading .bones, throw ClassNotFoundException :
    AnimatedGroup group = BonesIO.loadGroup(activity.getAssets().open(assetFileName));


Is this caused by Serializable obj? Why loading .ser is ok but .bones is not? Any main difference between them?

kiffa


kiffa

First the log said:

09-17 18:51:48.890: W/System.err(4142): java.lang.ClassNotFoundException: raft.jpct.bones.MeshData
09-17 18:51:48.890: W/System.err(4142):    at java.lang.Class.classForName(Native Method)
09-17 18:51:48.890: W/System.err(4142):    at java.lang.Class.forName(Class.java:234)
09-17 18:51:48.890: W/System.err(4142):    at java.io.ObjectInputStream.resolveClass(ObjectInputStream.java:2564)
09-17 18:51:48.890: W/System.err(4142):    at java.io.ObjectInputStream.readNewClassDesc(ObjectInputStream.java:1823)
09-17 18:51:48.890: W/System.err(4142):    at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:811)
09-17 18:51:48.890: W/System.err(4142):    at java.io.ObjectInputStream.readNewObject(ObjectInputStream.java:2039)
09-17 18:51:48.890: W/System.err(4142):    at java.io.ObjectInputStream.readNonPrimitiveContent(ObjectInputStream.java:916)
09-17 18:51:48.890: W/System.err(4142):    at java.io.ObjectInputStream.readObject(ObjectInputStream.java:2262)
09-17 18:51:48.890: W/System.err(4142):    at java.io.ObjectInputStream.readObject(ObjectInputStream.java:2217)
09-17 18:51:48.890: W/System.err(4142):    at b.a.a.a.<init>(Unknown Source)




Then i add "-keep  class raft.jpct.bones.MeshData" in progurad.cfg, the error changed to:

09-17 18:54:13.400: W/System.err(4211): java.io.InvalidClassException: raft.jpct.bones.MeshData; Incompatible class (SUID): raft.jpct.bones.MeshData: static final long serialVersionUID =1L; but expected raft.jpct.bones.MeshData: static final long serialVersionUID =7143378492676895671L;
09-17 18:54:13.400: W/System.err(4211):    at java.io.ObjectInputStream.verifyAndInit(ObjectInputStream.java:2697)
09-17 18:54:13.400: W/System.err(4211):    at java.io.ObjectInputStream.readNewClassDesc(ObjectInputStream.java:1825)
09-17 18:54:13.400: W/System.err(4211):    at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:811)
09-17 18:54:13.400: W/System.err(4211):    at java.io.ObjectInputStream.readNewObject(ObjectInputStream.java:2039)
09-17 18:54:13.400: W/System.err(4211):    at java.io.ObjectInputStream.readNonPrimitiveContent(ObjectInputStream.java:916)
09-17 18:54:13.400: W/System.err(4211):    at java.io.ObjectInputStream.readObject(ObjectInputStream.java:2262)
09-17 18:54:13.400: W/System.err(4211):    at java.io.ObjectInputStream.readObject(ObjectInputStream.java:2217)
09-17 18:54:13.400: W/System.err(4211):    at raft.jpct.bones.a.<init>(Unknown Source)
09-17 18:54:13.400: W/System.err(4211):    at raft.jpct.bones.c.<init>(Unknown Source)
09-17 18:54:13.400: W/System.err(4211):    at raft.jpct.bones.d.a(Unknown Source)
09-17 18:54:13.400: W/System.err(4211):    at com.zwenyu.k.g.b(Unknown Source)
09-17 18:54:13.400: W/System.err(4211):    at com.zwenyu.i.d.f(Unknown Source)
09-17 18:54:13.400: W/System.err(4211):    at com.zwenyu.i.d.d(Unknown Source)
09-17 18:54:13.400: W/System.err(4211):    at com.zwenyu.i.d.b(Unknown Source)
09-17 18:54:13.400: W/System.err(4211):    at com.zwenyu.i.d.a(Unknown Source)
09-17 18:54:13.400: W/System.err(4211):    at com.zwenyu.i.d.doInBackground(Unknown Source)
09-17 18:54:13.400: W/System.err(4211):    at android.os.AsyncTask$2.call(AsyncTask.java:185)
09-17 18:54:13.400: W/System.err(4211):    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:306)
09-17 18:54:13.400: W/System.err(4211):    at java.util.concurrent.FutureTask.run(FutureTask.java:138)
09-17 18:54:13.400: W/System.err(4211):    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1088)
09-17 18:54:13.400: W/System.err(4211):    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:581)
09-17 18:54:13.400: W/System.err(4211):    at java.lang.Thread.run(Thread.java:1019)
09-17 18:54:13.400: W/dalvikvm(4211): threadid=11: thread exiting with uncaught exception (group=0x401f8560)



raft

must be related to obfuscation. possibly serialVersionUID is changed during obfuscation. try adding that field to keep list

kiffa

Yes, it's related to obfuscation. I have resolve this by add:

-keepnames class * implements java.io.Serializable

-keepclassmembers class * implements java.io.Serializable {
    static final long serialVersionUID;
    private static final java.io.ObjectStreamField[] serialPersistentFields;
    !static !transient <fields>;
    private void writeObject(java.io.ObjectOutputStream);
    private void readObject(java.io.ObjectInputStream);
    java.lang.Object writeReplace();
    java.lang.Object readResolve();
}

The keep list above is not precise but workable.

raft