Author Topic: ClassNotFoundException when loading .bones with obfuscated code.  (Read 2861 times)

Offline kiffa

  • long
  • ***
  • Posts: 199
    • View Profile
I use android-proguard to Obfuscate my code, and ClassNotFoundException happened when  loading .bones. All are ok before obfuscated.

Codes:
Code: [Select]
//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?

Offline kiffa

  • long
  • ***
  • Posts: 199
    • View Profile
Re: ClassNotFoundException when loading .bones with obfuscated code.
« Reply #1 on: September 17, 2012, 11:17:44 am »
This may be caused by Proguard itself, i will have a look.

Offline kiffa

  • long
  • ***
  • Posts: 199
    • View Profile
Re: ClassNotFoundException when loading .bones with obfuscated code.
« Reply #2 on: September 17, 2012, 12:57:14 pm »
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)



Offline raft

  • Moderator
  • quad
  • *****
  • Posts: 1966
    • View Profile
    • http://www.aptalkarga.com
Re: ClassNotFoundException when loading .bones with obfuscated code.
« Reply #3 on: September 17, 2012, 02:03:21 pm »
must be related to obfuscation. possibly serialVersionUID is changed during obfuscation. try adding that field to keep list

Offline kiffa

  • long
  • ***
  • Posts: 199
    • View Profile
Re: ClassNotFoundException when loading .bones with obfuscated code.
« Reply #4 on: September 17, 2012, 02:08:33 pm »
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.

Offline raft

  • Moderator
  • quad
  • *****
  • Posts: 1966
    • View Profile
    • http://www.aptalkarga.com
Re: ClassNotFoundException when loading .bones with obfuscated code.
« Reply #5 on: September 17, 2012, 02:11:26 pm »
cool, so you had solved the issue?