4

我的代码已经运行了一年多,在其他地方更改了一些代码后,我没有更改其中的任何代码,MainActivity这是第一种形式。我现在得到这个error: java.lang.reflect.InvocationTargetException,然后java.lang.NoClassDefFoundError: com/google/gson/Gson在尝试这个时:

   Gson gson = new Gson();

我还有其他使用 Gson 的程序,它们运行良好。我的项目的 libs 文件夹中有 gson-2.2.4。我已经尝试了几个小时阅读所有其他类似的问题,但我被困住了。猫日志:

06-06 01:47:25.935: I/System.out(4393): debugger has settled (1304)
06-06 01:47:26.120: E/dalvikvm(4393): Could not find class 'com.google.gson.Gson', referenced from method com.comcasystems.routedriver.MainActivity.onCreate
06-06 01:47:26.120: W/dalvikvm(4393): VFY: unable to resolve new-instance 133 (Lcom/google/gson/Gson;) in Lcom/comcasystems/routedriver/MainActivity;
06-06 01:47:26.120: D/dalvikvm(4393): VFY: replacing opcode 0x22 at 0x000b
06-06 01:47:26.120: D/dalvikvm(4393): DexOpt: unable to opt direct call 0x0206 at 0x0d in Lcom/comcasystems/routedriver/MainActivity;.onCreate
06-06 01:47:26.170: E/dalvikvm(4393): Could not find class 'com.google.gson.Gson', referenced from method com.comcasystems.routedriver.MainActivity$1.handleMessage
06-06 01:47:26.170: W/dalvikvm(4393): VFY: unable to resolve new-instance 133 (Lcom/google/gson/Gson;) in Lcom/comcasystems/routedriver/MainActivity$1;
06-06 01:47:26.175: D/dalvikvm(4393): VFY: replacing opcode 0x22 at 0x0024
4

1 回答 1

3

请注意您在 Java 构建路径中包含 Gson 库,并检查是否正确配置了 proguard:

# proguard configuration for Gson
-keepattributes Signature
-keep public class com.google.gson
-keep class sun.misc.Unsafe { *; }

-keep class com.comcasystems.routedriver.jsonclasses.** { *; }

注意:最后一个条目只是 Json 类的符号占位符,可保护它们不被混淆。您必须在此处列出所有受影响的类。

希望这会有所帮助......干杯!

于 2013-06-06T06:13:03.430 回答