Okhttp NoClassDefFoundError
Asked Answered
P

3

5

I am using OkHttp 2.0.0 jar in my android application on eclipse. As OkHttp is now dependent on Okio library, I also added Okio 1.0.0 jar in my project.The project compiles fine with no compilation errors but when I run on my android device, it gives me this NoClassDefFoundError all relating to the OkHttp library classes.

I have placed all the jars in my libs folder of the project and added them to my build path and also tried checking them in the Export and Order Tab, but still it is not working.

I wanted to know since okhttp is dependent on okio, will just adding both jars would work fine or would I have to do anything different.

I have also tried the volley jar and it works all fine without any trouble.Anyone could help me out here, the problem is around for now 3 to 4 days.

Update I also tried the android studio and added the okhttp library in the build dependency but still not working.

Parget answered 6/7, 2014 at 10:21 Comment(0)
L
1

In OkHttp 2.0.0 the language level was updated to Java 7.

See Change log here https://github.com/square/okhttp/blob/master/CHANGELOG.md

In order to fix the issue you will need to update to java 7.

Also at this point you may also need change the target sdk to kitkat (API 19), and update your build tools etc in order for android to play nice with java 7


EDIT: I had the same problem when i upgraded to okHttp 2.0.0 and built with ant. Although the build seemed to succeed i got the NoClassDefFoundError. Going through my build logs I had a whole bunch of silent errors

The first came from javac

warning: com/squareup/okhttp/<classname>.class major version 51 is newer than 50, the highest major version supported by this compiler.

and the second from dex

[dx] trouble processing:
[dx] bad class file magic (cafebabe) or version (0033.0000)
[dx] ...while parsing com/squareup/okhttp/<classname>.class
[dx] ...while processing com/squareup/okhttp/<classname>.class
Lustick answered 7/7, 2014 at 12:42 Comment(5)
I also tried tried downloading the source and tried compiling the source using maven myself but still not working. As maven build was successful that means there is no problem in my java version (I have java 7) . Also in change log it says android 2.3 so there no problem.Parget
@KishuAgarwal have a look at your build logs there might be some hints there. I've updated my answer to show logging that I had when I was experiencing this problemLustick
thanks for your reply. You are right, I did see those bad class file magic errors in my build. I will try updating my java version.Parget
@KishuAgarwal if that doesn't fix it try the second part of my answer and update your build tools and target kitkatLustick
Problem Fixed. Java update didn't do anything but by changing my sdk from 18 to 19 solved the problem. Thank you for recommending that. I was frustated for so much time on this problem.Parget
N
7

OkHttp v2.0 depends on Okio v1.0. You can download its jar here. This worked for me

Reference from https://github.com/square/okhttp/issues/870

Noose answered 27/8, 2014 at 12:59 Comment(2)
what do you mean "this worked for me". DId you just imported that lib to project?Opia
download jar file and add jar reference to the moduleNoose
L
1

In OkHttp 2.0.0 the language level was updated to Java 7.

See Change log here https://github.com/square/okhttp/blob/master/CHANGELOG.md

In order to fix the issue you will need to update to java 7.

Also at this point you may also need change the target sdk to kitkat (API 19), and update your build tools etc in order for android to play nice with java 7


EDIT: I had the same problem when i upgraded to okHttp 2.0.0 and built with ant. Although the build seemed to succeed i got the NoClassDefFoundError. Going through my build logs I had a whole bunch of silent errors

The first came from javac

warning: com/squareup/okhttp/<classname>.class major version 51 is newer than 50, the highest major version supported by this compiler.

and the second from dex

[dx] trouble processing:
[dx] bad class file magic (cafebabe) or version (0033.0000)
[dx] ...while parsing com/squareup/okhttp/<classname>.class
[dx] ...while processing com/squareup/okhttp/<classname>.class
Lustick answered 7/7, 2014 at 12:42 Comment(5)
I also tried tried downloading the source and tried compiling the source using maven myself but still not working. As maven build was successful that means there is no problem in my java version (I have java 7) . Also in change log it says android 2.3 so there no problem.Parget
@KishuAgarwal have a look at your build logs there might be some hints there. I've updated my answer to show logging that I had when I was experiencing this problemLustick
thanks for your reply. You are right, I did see those bad class file magic errors in my build. I will try updating my java version.Parget
@KishuAgarwal if that doesn't fix it try the second part of my answer and update your build tools and target kitkatLustick
Problem Fixed. Java update didn't do anything but by changing my sdk from 18 to 19 solved the problem. Thank you for recommending that. I was frustated for so much time on this problem.Parget
V
0

Go to Project/Properties/Java Build Path/Order and Export -- Make sure there's a check in front of Android Dependencies and the support library, if you use it. Mark all checkboxes and Click on Apply and clean the project.

Viccora answered 7/7, 2014 at 12:47 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.