NoClassDefFoundError Gson

My code has been working fine for over a year now, and after changing the code in other places, I did not change the code in MainActivity and this is the first form. Now I get this error: java.lang.reflect.InvocationTargetException , and then java.lang.NoClassDefFoundError: com/google/gson/Gson when trying:

  Gson gson = new Gson(); 

I have other programs where I use Gson and they work great. I have gson-2.2.4 in the libs folder in my project. I tried for hours to read all the other similar problems, but I was stuck. Cat Magazine:

 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
source share
1 answer

Make sure you include the Gson library in the Java build path and make sure that proguard is configured accordingly:

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

Note: the last entry is just a symbolic placeholder for your Json classes, which protects them from obfuscation. Here you should list all the classes affected.

Hope this helps ... Greetings!

+2
source

Source: https://habr.com/ru/post/1484765/


All Articles