使用proguard后在.jar中出现InvalidClassCastException



我正在使用eclipse开发一个android应用程序。当我按下运行(绿色三角形)时,该应用程序工作正常。但是,我启用了proguard,程序崩溃了。我使用默认的proguard-android.txt,它存在于sdk/tools/proguard中。

我有一个名为Software.jar的jar,其中有几个类。其中之一(Data)是一个可序列化的类。(with serialversionUID=112358L)。这(可能)是导致错误的部分。

这是错误日志(我不知道为什么,但它显示为黄色作为警告):

07-22 15:29:46.429: W/System.err(2051): java.io.InvalidClassException:software.Data;SUID (Incompatible class): software。数据:静态终值serialVersionUID =112358L;但是预期的软件。静态数据:最终长serialVersionUID =-4551990835091843772L;07-2215:29:46.433: W/System.err(2051): atjava.io.ObjectInputStream.verifyAndInit (ObjectInputStream.java: 2380)07-22 15:29:46.433: W/System.err(2051): atjava.io.ObjectInputStream.readNewClassDesc (ObjectInputStream.java: 1662)07-22 15:29:46.437: W/System.err(2051): atjava.io.ObjectInputStream.readClassDesc (ObjectInputStream.java: 683)07-22 15:29:46.437: W/System.err(2051): atjava.io.ObjectInputStream.readNewObject (ObjectInputStream.java: 1803)07-22 15:29:46.44: W/System.err(2051): atjava.io.ObjectInputStream.readNonPrimitiveContent (ObjectInputStream.java: 787)07-22 15:29:46.44: W/System.err(2051): atjava.io.ObjectInputStream.readObject (ObjectInputStream.java: 2003)07-22 15:29:46.44: W/System.err(2051): atjava.io.ObjectInputStream.readObject (ObjectInputStream.java: 1960)07-22 15:29:46.445: W/System.err(2051): atjava.util.ArrayList.readObject(ArrayList.java:657) 07-22 15:29:46.445:W/System.err(2051): at java.lang.reflect.Method.invokeNative(原生的)方法)07-22 15:29:46.449:W/System.err(2051): atjava.lang.reflect.Method.invoke(Method.java:511) 07-22 15:29:46.449:(2051): W/system . errjava.io.ObjectInputStream.readObjectForClass (ObjectInputStream.java: 1354)07-22 15:29:46.449: W/System.err(2051): atjava.io.ObjectInputStream.readHierarchy (ObjectInputStream.java: 1266)07-22 15:29:46.453: W/System.err(2051): atjava.io.ObjectInputStream.readNewObject (ObjectInputStream.java: 1855)07-22 15:29:46.453: W/System.err(2051): atjava.io.ObjectInputStream.readNonPrimitiveContent (ObjectInputStream.java: 787)07-22 15:29:46.457: W/System.err(2051): atjava.io.ObjectInputStream.readObject (ObjectInputStream.java: 2003)07-22 15:29:46.457: W/System.err(2051): atjava.io.ObjectInputStream.readObject (ObjectInputStream.java: 1960)07-22 15:29:46.457: W/System.err(2051): atcom.mainpackage.FullGenPhysics。a(未知来源)07-22 15:29:46.457:W/System.err(2051): at com.mainpackage.de.run(未知来源)

这些是红线(标签错误)

07-22 15:29:46.465: E/AndroidRuntime(2051): FATAL EXCEPTION:Thread-161 07-22 15:29:46.465: E/AndroidRuntime(2051):java.lang.NullPointerException 07-22 15:29:46.465:E/AndroidRuntime(2051): at software.Gen_Phy。a(来源不明)07-2215:29:46.465: E/AndroidRuntime(2051): at software. gen_phya(未知)来源)07-22 15:29:46.465:E/AndroidRuntime(2051): atsoftware.Gen_Phy。(未知来源)07-22 15:29:46.465:E/AndroidRuntime(2051): at com.mainpackage.FullGenPhysics.a(未知来源)07-22 15:29:46.465:E/AndroidRuntime(2051): atcom.mainpackage.de.run(未知来源)07-22 15:29:46.465:W/ActivityManager(333):强制完成活动com.mainpackage/。FullGenPhysics 07-22 15:29:46.525:E/SocketStream(112): readFully was waiting for 403440 bytes, got for 4915207-22 15:29:46.525: E/SocketStream(112): readFully was waiting .日志示例354288字节,得到16384 07-22 15:29:46.529:E/SocketStream(112):readFully正在等待337904字节,得到1624 07-22 15:29:46.529:E/SocketStream(112): readFully was waiting for 336280 bytes, got for 4915207-22 15:29:46.533: E/SocketStream(112): readFully was waiting .日志示例287128字节,得到16384 07-22 15:29:46.533:E/SocketStream(112):readFully正在等待270744字节,得到1624 07-22 15:29:46.537:E/SocketStream(112): readFully是等待269120字节,得到4915207-22 15:29:46.537: E/SocketStream(112): readFully was waiting .日志示例219968 bytes, get 16384 07-22 15:29:46.537: E/SocketStream(112):readFully正在等待203584字节,得到1624 07-22 15:29:46.541:E/SocketStream(112): readFully正在等待201960字节,得到4915207-22 15:29:46.541: E/SocketStream(112): readFully was waiting .日志示例152808 bytes, got 16384 07-22 15:29:46.541: E/SocketStream(112):readFully正在等待136424字节,得到1624 07-22 15:29:46.545:E/SocketStream(112): readFully was waiting for 134800 bytes, got for 4915207-22 15:29:46.545: E/SocketStream(112): readFully was waiting .日志示例85648字节,得到16384 07-22 15:29:46.549:E/SocketStream(112):readFully正在等待69264字节,得到1624 07-22 15:29:46.549:E/SocketStream(112): readFully was waiting for 67640 bytes, got for 4915207-22 15:29:46.549: E/SocketStream(112): readFully was waiting .日志示例18488字节,得到16384

有趣的是,我有一个系统。在software.jar的一个类中。这是打印出来的。

我试过添加-libraryjars C:UsersHarshgitmarks++Marks++Software.jar以及

-keep  class Software.**

到前面提到的。txt文件

我哪里错了?

编辑

07-22 16:10:54.957: W/System.err(2233): java.lang.ClassNotFoundException: software.Data
07-22 16:10:54.961: W/System.err(2233):   at java.lang.Class.classForName(Native Method)
07-22 16:10:54.961: W/System.err(2233):   at java.lang.Class.forName(Class.java:217)
07-22 16:10:54.965: W/System.err(2233):   at java.io.ObjectInputStream.resolveClass(ObjectInputStream.java:2301)
07-22 16:10:54.965: W/System.err(2233):   at java.io.ObjectInputStream.readNewClassDesc(ObjectInputStream.java:1660)
07-22 16:10:54.965: W/System.err(2233):   at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:683)
07-22 16:10:54.969: W/System.err(2233):   at java.io.ObjectInputStream.readNewObject(ObjectInputStream.java:1803)
07-22 16:10:54.969: W/System.err(2233):   at java.io.ObjectInputStream.readNonPrimitiveContent(ObjectInputStream.java:787)
07-22 16:10:54.973: W/System.err(2233):   at java.io.ObjectInputStream.readObject(ObjectInputStream.java:2003)
07-22 16:10:54.973: W/System.err(2233):   at java.io.ObjectInputStream.readObject(ObjectInputStream.java:1960)
07-22 16:10:54.973: W/System.err(2233):   at java.util.ArrayList.readObject(ArrayList.java:657)
07-22 16:10:54.973: W/System.err(2233):   at java.lang.reflect.Method.invokeNative(Native Method)
07-22 16:10:54.977: W/System.err(2233):   at java.lang.reflect.Method.invoke(Method.java:511)
07-22 16:10:54.977: W/System.err(2233):   at java.io.ObjectInputStream.readObjectForClass(ObjectInputStream.java:1354)
07-22 16:10:54.977: W/System.err(2233):   at java.io.ObjectInputStream.readHierarchy(ObjectInputStream.java:1266)
07-22 16:10:54.977: W/System.err(2233):   at java.io.ObjectInputStream.readNewObject(ObjectInputStream.java:1855)
07-22 16:10:54.977: W/System.err(2233):   at java.io.ObjectInputStream.readNonPrimitiveContent(ObjectInputStream.java:787)
07-22 16:10:54.977: W/System.err(2233):   at java.io.ObjectInputStream.readObject(ObjectInputStream.java:2003)
07-22 16:10:54.977: W/System.err(2233):   at java.io.ObjectInputStream.readObject(ObjectInputStream.java:1960)
07-22 16:10:54.977: W/System.err(2233):   at com.mainpackage.FullGenPhysics.a(Unknown Source)
07-22 16:10:54.977: W/System.err(2233):   at com.mainpackage.de.run(Unknown Source)
07-22 16:10:54.981: W/System.err(2233): Caused by: java.lang.NoClassDefFoundError: software/Data
07-22 16:10:54.981: W/System.err(2233):   ... 20 more
07-22 16:10:54.981: W/System.err(2233): Caused by: java.lang.ClassNotFoundException: software.Data
07-22 16:10:54.981: W/System.err(2233):   at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
07-22 16:10:54.981: W/System.err(2233):   at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
07-22 16:10:54.981: W/System.err(2233):   at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
07-22 16:10:54.985: W/System.err(2233):   ... 20 more

似乎在经历了proguard之后,你的serializable类的serialVersionUID正在改变。您需要更改configuration of proguard以包含:

-keepclassmembers class software.Data {
static final long serialVersionUID;
}

如下所述

经过一些试验,我找到了一个可行的解决方案。这是我使用的:

-libraryjars Software.jar
-keep  class software.**{
*;
}

相关内容

  • 没有找到相关文章

最新更新