I am getting very interesting bug in one of my apps. My app is working fine on android L, But as soon as i try to run it on other android versions, I am getting ClassNotFoundException or NoClassDefFoundError while trying to call web services using Retrofit, even though all those classes are existing and working fine on my android L device. I don't know what's happening right now, app is running in other versions as long as i don't make a Network Request but as soon as i go for Network Request, it gives me either ClassNotFoundException or NoClassDefFoundError. Also I am using Android Studio, so if someone has faced this kind of issue earlier, then please help, i am in severe need.
NOTE : App is working fine on Android L and also classes in which i am getting ClassNotFoundException or NoClassDefFoundError are not version specific i.e it was not like that they are supported in android L or so. All classes in which i am getting these errors are general custom/model classes and has no link with the higher android versions or something.
And these are my Logcat errors
This is the exception while hitting login api
java.lang.TypeNotPresentException: Type com.codebrew.embazaar.pojo.UserLoginPojo not present
at libcore.reflect.ParameterizedTypeImpl.getRawType(ParameterizedTypeImpl.java:63)
at libcore.reflect.ParameterizedTypeImpl.getResolvedType(ParameterizedTypeImpl.java:72)
at libcore.reflect.ListOfTypes.resolveTypes(ListOfTypes.java:70)
at libcore.reflect.ListOfTypes.getResolvedTypes(ListOfTypes.java:55)
at libcore.reflect.ParameterizedTypeImpl.getResolvedType(ParameterizedTypeImpl.java:71)
at libcore.reflect.ListOfTypes.resolveTypes(ListOfTypes.java:70)
at libcore.reflect.ListOfTypes.getResolvedTypes(ListOfTypes.java:55)
at libcore.reflect.Types.getTypeArray(Types.java:50)
at java.lang.reflect.Method.getGenericParameterTypes(Method.java:216)
at retrofit.RestMethodInfo.parseResponseType(RestMethodInfo.java:250)
at retrofit.RestMethodInfo.<init>(RestMethodInfo.java:97)
at retrofit.RestAdapter.getMethodInfo(RestAdapter.java:213)
at retrofit.RestAdapter$RestHandler.invoke(RestAdapter.java:236)
at $Proxy0.userLogin(Native Method)
at com.codebrew.embazaar.MainActivity.loginUser(MainActivity.java:529)
at com.codebrew.embazaar.MainActivity.onClick(MainActivity.java:324)
at android.view.View.performClick(View.java:4748)
at android.view.View$PerformClick.run(View.java:19535)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:146)
at android.app.ActivityThread.main(ActivityThread.java:5679)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1291)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1107)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.ClassNotFoundException: com.codebrew.embazaar.pojo.UserLoginPojo
at java.lang.Class.classForName(Native Method)
at java.lang.Class.forName(Class.java:251)
at libcore.reflect.ParameterizedTypeImpl.getRawType(ParameterizedTypeImpl.java:61)
at libcore.reflect.ParameterizedTypeImpl.getResolvedType(ParameterizedTypeImpl.java:72)
at libcore.reflect.ListOfTypes.resolveTypes(ListOfTypes.java:70)
at libcore.reflect.ListOfTypes.getResolvedTypes(ListOfTypes.java:55)
at libcore.reflect.ParameterizedTypeImpl.getResolvedType(ParameterizedTypeImpl.java:71)
at libcore.reflect.ListOfTypes.resolveTypes(ListOfTypes.java:70)
at libcore.reflect.ListOfTypes.getResolvedTypes(ListOfTypes.java:55)
at libcore.reflect.Types.getTypeArray(Types.java:50)
at java.lang.reflect.Method.getGenericParameterTypes(Method.java:216)
at retrofit.RestMethodInfo.parseResponseType(RestMethodInfo.java:250)
at retrofit.RestMethodInfo.<init>(RestMethodInfo.java:97)
at retrofit.RestAdapter.getMethodInfo(RestAdapter.java:213)
at retrofit.RestAdapter$RestHandler.invoke(RestAdapter.java:236)
at $Proxy0.userLogin(Native Method)
at com.codebrew.embazaar.MainActivity.loginUser(MainActivity.java:529)
at com.codebrew.embazaar.MainActivity.onClick(MainActivity.java:324)
at android.view.View.performClick(View.java:4748)
at android.view.View$PerformClick.run(View.java:19535)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:146)
at android.app.ActivityThread.main(ActivityThread.java:5679)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1291)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1107)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NoClassDefFoundError: com/codebrew/embazaar/pojo/UserLoginPojo
at java.lang.Class.classForName(Native Method)
at java.lang.Class.forName(Class.java:251)
at libcore.reflect.ParameterizedTypeImpl.getRawType(ParameterizedTypeImpl.java:61)
at libcore.reflect.ParameterizedTypeImpl.getResolvedType(ParameterizedTypeImpl.java:72)
at libcore.reflect.ListOfTypes.resolveTypes(ListOfTypes.java:70)
at libcore.reflect.ListOfTypes.getResolvedTypes(ListOfTypes.java:55)
at libcore.reflect.ParameterizedTypeImpl.getResolvedType(ParameterizedTypeImpl.java:71)
at libcore.reflect.ListOfTypes.resolveTypes(ListOfTypes.java:70)
at libcore.reflect.ListOfTypes.getResolvedTypes(ListOfTypes.java:55)
at libcore.reflect.Types.getTypeArray(Types.java:50)
at java.lang.reflect.Method.getGenericParameterTypes(Method.java:216)
at retrofit.RestMethodInfo.parseResponseType(RestMethodInfo.java:250)
at retrofit.RestMethodInfo.<init>(RestMethodInfo.java:97)
at retrofit.RestAdapter.getMethodInfo(RestAdapter.java:213)
at retrofit.RestAdapter$RestHandler.invoke(RestAdapter.java:236)
at $Proxy0.userLogin(Native Method)
at com.codebrew.embazaar.MainActivity.loginUser(MainActivity.java:529)
at com.codebrew.embazaar.MainActivity.onClick(MainActivity.java:324)
at android.view.View.performClick(View.java:4748)
at android.view.View$PerformClick.run(View.java:19535)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:146)
at android.app.ActivityThread.main(ActivityThread.java:5679)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1291)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1107)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.codebrew.embazaar.pojo.UserLoginPojo" on path: DexPathList[[zip file "/data/app/com.codebrew.embazaar-11.apk"],nativeLibraryDirectories=[/data/app-lib/com.codebrew.embazaar-11, /vendor/lib, /system/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:67)
at java.lang.ClassLoader.loadClass(ClassLoader.java:497)
at java.lang.ClassLoader.loadClass(ClassLoader.java:457)
at java.lang.Class.classForName(Native Method)
at java.lang.Class.forName(Class.java:251)
at libcore.reflect.ParameterizedTypeImpl.getRawType(ParameterizedTypeImpl.java:61)
at libcore.reflect.ParameterizedTypeImpl.getResolvedType(ParameterizedTypeImpl.java:72)
at libcore.reflect.ListOfTypes.resolveTypes(ListOfTypes.java:70)
at libcore.reflect.ListOfTypes.getResolvedTypes(ListOfTypes.java:55)
at libcore.reflect.ParameterizedTypeImpl.getResolvedType(ParameterizedTypeImpl.java:71)
at libcore.reflect.ListOfTypes.resolveTypes(ListOfTypes.java:70)
at libcore.reflect.ListOfTypes.getResolvedTypes(ListOfTypes.java:55)
at libcore.reflect.Types.getTypeArray(Types.java:50)
at java.lang.reflect.Method.getGenericParameterTypes(Method.java:216)
at retrofit.RestMethodInfo.parseResponseType(RestMethodInfo.java:250)
at retrofit.RestMethodInfo.<init>(RestMethodInfo.java:97)
at retrofit.RestAdapter.getMethodInfo(RestAdapter.java:213)
at retrofit.RestAdapter$RestHandler.invoke(RestAdapter.java:236)
at $Proxy0.userLogin(Native Method)
at com.codebrew.embazaar.MainActivity.loginUser(MainActivity.java:529)
at com.codebrew.embazaar.MainActivity.onClick(MainActivity.java:324)
at android.view.View.performClick(View.java:4748)
at android.view.View$PerformClick.run(View.java:19535)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:146)
at android.app.ActivityThread.main(ActivityThread.java:5679)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1291)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1107)
at dalvik.system.NativeStart.main(Native Method)
and this one i am getting while hitting forgot password network request
java.lang.NoClassDefFoundError: com.codebrew.embazaar.MainActivity$7$1
at com.codebrew.embazaar.MainActivity$7.onClick(MainActivity.java:392)
at android.view.View.performClick(View.java:4748)
at android.view.View$PerformClick.run(View.java:19535)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:146)
at android.app.ActivityThread.main(ActivityThread.java:5679)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1291)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1107)
at dalvik.system.NativeStart.main(Native Method)
**IMPORTANT: As I debugged my code, am getting TypeNotPresentException which is an unchecked exception followed by these ClassNotFoundException or NoClassDefFoundError. I am mentioning this here because i think may be this thing can make some clarity about my question/problem.
Here is my MainActivity CommonPojo and gradle file