Prabal.PX
Prabal.PX

Reputation: 33

java.lang.NoClassDefFoundError: Failed resolution of: Lokhttp3/MediaType;

Using okhttp-3.0.1.jar results in a crash:

 02-25 17:44:33.279: E/AndroidRuntime(30263): FATAL EXCEPTION: main
 02-25 17:44:33.279: E/AndroidRuntime(30263): Process:com.littleapproom.diamondapp, PID: 30263
 02-25 17:44:33.279: E/AndroidRuntime(30263):java.lang.NoClassDefFoundError: Failed resolution  Lokhttp3/MediaType;
 02-25 17:44:33.279: E/AndroidRuntime(30263):   at com.littleapproom.diamondapp.helper.ServiceTask.<clinit>(ServiceTask.java:68)
 02-25 17:44:33.279: E/AndroidRuntime(30263):   at com.littleapproom.diamondapp.RegisterActivity.callRegisterApi(RegisterActivity.java:74)
 02-25 17:44:33.279: E/AndroidRuntime(30263):   at com.littleapproom.diamondapp.RegisterActivity.onClick(RegisterActivity.java:50)
 02-25 17:44:33.279: E/AndroidRuntime(30263):   at android.view.View.performClick(View.java:4785)
 02-25 17:44:33.279: E/AndroidRuntime(30263):   at android.view.View$PerformClick.run(View.java:19884)
 02-25 17:44:33.279: E/AndroidRuntime(30263):   at android.os.Handler.handleCallback(Handler.java:739)
 02-25 17:44:33.279: E/AndroidRuntime(30263):   at  android.os.Handler.dispatchMessage(Handler.java:95)
 02-25 17:44:33.279: E/AndroidRuntime(30263):   at android.os.Looper.loop(Looper.java:135)
 02-25 17:44:33.279: E/AndroidRuntime(30263):   at android.app.ActivityThread.main(ActivityThread.java:5343)
 02-25 17:44:33.279: E/AndroidRuntime(30263):   at java.lang.reflect.Method.invoke(Native Method)
 02-25 17:44:33.279: E/AndroidRuntime(30263):   at java.lang.reflect.Method.invoke(Method.java:372)
 02-25 17:44:33.279: E/AndroidRuntime(30263):   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:905)
 02-25 17:44:33.279: E/AndroidRuntime(30263):   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:700)
 02-25 17:44:33.279: E/AndroidRuntime(30263): Caused by: java.lang.ClassNotFoundException: Didn't find class "okhttp3.MediaType" on path: DexPathList[[zip file "/data/app/com.littleapproom.diamondapp-1/base.apk"],nativeLibraryDirectories=[/vendor/lib, /system/lib]]
 02-25 17:44:33.279: E/AndroidRuntime(30263):   at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
 02-25 17:44:33.279: E/AndroidRuntime(30263):   at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
 02-25 17:44:33.279: E/AndroidRuntime(30263):   at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
 02-25 17:44:33.279: E/AndroidRuntime(30263):   ... 13 more
 02-25 17:44:33.279: E/AndroidRuntime(30263):   Suppressed: java.lang.ClassNotFoundException: okhttp3.MediaType
 02-25 17:44:33.279: E/AndroidRuntime(30263):       at java.lang.Class.classForName(Native Method)
 02-25 17:44:33.279: E/AndroidRuntime(30263):       at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
 02-25 17:44:33.279: E/AndroidRuntime(30263):       at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
 02-25 17:44:33.279: E/AndroidRuntime(30263):       at   java.lang.ClassLoader.loadClass(ClassLoader.java:504)
 02-25 17:44:33.279: E/AndroidRuntime(30263):       ... 14 more
  02-25 17:44:33.279: E/AndroidRuntime(30263):  Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack available

okhttp-3.0.1.jar works fine and has this missing class. please help for solution.

Upvotes: 1

Views: 5920

Answers (2)

Hanu
Hanu

Reputation: 1117

THIS MIGHT NOT BE AN ANSWER. I havent got sufficient Rep to comment, hence I am placing this as an answer.

Have you imported a custom library that might be using okhttp or are you using okhttp in your project directly? I too came across this problem when I was importing a library that might have used okhttp. I have to explicitly include okhttp into my gradle to overcome this problem though I didnt use it in my code but the imported aar used it . Your case might not be the same but sharing more info on this, like your project structure and relevant code might help to resolve this.

Upvotes: 3

AllDayAmazing
AllDayAmazing

Reputation: 2383

This seems to be a build system issue. As mentioned in this thread on the OKHttp site, it seems that OkHttp3 was not included in one of the libraries used. In my case, it was an issue with the .aar I was compiling, not pulling in the library. There are a few ways to solve this, but from what I can tell, the best seems to be building to a local maven repo: instructions are found in the S/O answer

Also, just discovered was this grade command to copy the libraries to your local for building the .aar: found on this SO post

From other info found on the web:

There is no automated way to package the dependencies of the library inside the aar. This is contrary to proper dependency management and can lead to problems down the line.

If you really want to do this, you'd have to gather the dependencies manually (using code in build.gradle) and manually package the files in the aar.

Upvotes: 0

Related Questions