Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Could not use 'com.squareup.okhttp3:okhttp-urlconnection:3.0.0' (gradle) #2243

Closed
BoD opened this issue Jan 14, 2016 · 13 comments
Closed

Could not use 'com.squareup.okhttp3:okhttp-urlconnection:3.0.0' (gradle) #2243

BoD opened this issue Jan 14, 2016 · 13 comments

Comments

@BoD
Copy link

BoD commented Jan 14, 2016

I am building an Android app.
When declaring these 2 dependencies:

    compile 'com.squareup.okhttp3:okhttp:3.0.0'
    compile 'com.squareup.okhttp3:okhttp-urlconnection:3.0.0'

my build fails with this error:

UNEXPECTED TOP-LEVEL EXCEPTION:
com.android.dex.DexException: Multiple dex files define Lokhttp3/Address;
        at com.android.dx.merge.DexMerger.readSortableTypes(DexMerger.java:579)
        at com.android.dx.merge.DexMerger.getSortedTypes(DexMerger.java:535)
        at com.android.dx.merge.DexMerger.mergeClassDefs(DexMerger.java:517)
        at com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:164)
        at com.android.dx.merge.DexMerger.merge(DexMerger.java:188)
        at com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:504)
        at com.android.dx.command.dexer.Main.runMonoDex(Main.java:334)
        at com.android.dx.command.dexer.Main.run(Main.java:277)
        at com.android.dx.command.dexer.Main.main(Main.java:245)
        at com.android.dx.command.Main.main(Main.java:106)

When looking at okhttp-urlconnection.jar I was surprised to see this class indeed present inside. I am not sure if this is normal.

I tried to be clever and declare instead these dependencies:

//    compile 'com.squareup.okhttp3:okhttp:3.0.0'
    compile ('com.squareup.okhttp3:okhttp-urlconnection:3.0.0') { exclude group: 'com.squareup.okhttp3' }

(notice the first declaration is commented out)

Now the build succeeds. But my app fails at runtime, with this exception:

java.lang.NoClassDefFoundError: Failed resolution of: Lokhttp3/internal/tls/OkHostnameVerifier;
                                                                                            at okhttp3.OkHttpClient$Builder.<init>(OkHttpClient.java:340)
                                                                                            at okhttp3.OkHttpClient.<init>(OkHttpClient.java:147)
                                                                                            at myapp.backend.net.MultipartHttpClient.getOkHttpClient(MultipartHttpClient.java:166)
                                                                                            at myapp.backend.net.MultipartHttpClient.getMultipartClientHttpRequest(MultipartHttpClient.java:135)
                                                                                            at myapp.backend.net.MultipartHttpClient.doHttpCall(MultipartHttpClient.java:273)
                                                                                            at myapp.core.codec.impl.ApiClientRequestImpl.doRequest(ApiClientRequestImpl.java:307)
                                                                                            at myapp.GcmReceiver.sendDeviceSetConfig(GcmReceiver.java:173)
                                                                                            at myapp.GcmReceiver$1.background(GcmReceiver.java:83)
                                                                                            at myapp.SimpleAsyncTask.doInBackground(SimpleAsyncTask.java:32)
                                                                                            at myapp.util.SimpleAsyncTask.doInBackground(SimpleAsyncTask.java:16)
                                                                                            at android.os.AsyncTask$2.call(AsyncTask.java:288)
                                                                                            at java.util.concurrent.FutureTask.run(FutureTask.java:237)
                                                                                            at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
                                                                                            at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
                                                                                            at java.lang.Thread.run(Thread.java:818)
                                                                                         Caused by: java.lang.ClassNotFoundException: Didn't find class "okhttp3.internal.tls.OkHostnameVerifier" on path: DexPathList[[zip file "/data/app/com.familyandco.mifamily.dev-2/base.apk"],nativeLibraryDirectories=[/vendor/lib, /system/lib]]
                                                                                            at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
                                                                                            at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
                                                                                            at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
                                                                                            at okhttp3.OkHttpClient$Builder.<init>(OkHttpClient.java:340) 
                                                                                            at okhttp3.OkHttpClient.<init>(OkHttpClient.java:147) 
                                                                                            at myapp.backend.net.MultipartHttpClient.getOkHttpClient(MultipartHttpClient.java:166) 
                                                                                            at myapp.backend.net.MultipartHttpClient.getMultipartClientHttpRequest(MultipartHttpClient.java:135) 
                                                                                            at myapp.backend.net.MultipartHttpClient.doHttpCall(MultipartHttpClient.java:273) 
                                                                                            at myapp.core.codec.impl.ApiClientRequestImpl.doRequest(ApiClientRequestImpl.java:307) 
                                                                                            at myapp.gcm.GcmReceiver.sendDeviceSetConfig(GcmReceiver.java:173) 
                                                                                            at myapp.gcm.GcmReceiver$1.background(GcmReceiver.java:83) 
                                                                                            at myapp.util.SimpleAsyncTask.doInBackground(SimpleAsyncTask.java:32) 
                                                                                            at myapp.util.SimpleAsyncTask.doInBackground(SimpleAsyncTask.java:16) 
                                                                                            at android.os.AsyncTask$2.call(AsyncTask.java:288) 
                                                                                            at java.util.concurrent.FutureTask.run(FutureTask.java:237) 
                                                                                            at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112) 
                                                                                            at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587) 
                                                                                            at java.lang.Thread.run(Thread.java:818) 
                                                                                            Suppressed: java.lang.ClassNotFoundException: okhttp3.internal.tls.OkHostnameVerifier
                                                                                            at java.lang.Class.classForName(Native Method)
                                                                                            at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
                                                                                            at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
                                                                                            at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
                                                                                                    ... 16 more
                                                                                         Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack available

Weird?

@nicolasjafelle
Copy link

I have the same issue

@ValleZ
Copy link

ValleZ commented Jan 14, 2016

Probably it's bit early to call v3.0.0 a stable version.

@JakeWharton
Copy link
Member

It's stable.

On Thu, Jan 14, 2016 at 11:51 AM Valentin Konovalov <
notifications@github.com> wrote:

Probably it's bit early to call v3.0.0 a stable version.


Reply to this email directly or view it on GitHub
#2243 (comment).

@ValleZ
Copy link

ValleZ commented Jan 14, 2016

I'm glad to hear this, Jake. Unfortunately it doesn't compile for most common scenarios because of the issue. Any plans to support picasso with okhttp3?

@iNoles
Copy link
Contributor

iNoles commented Jan 14, 2016

@BoD why you still have exclude line on the urlconnection one if you comment first one?

@BoD
Copy link
Author

BoD commented Jan 14, 2016

@iNoles Gradle knows that okhttp-urlconnection depends on okhttp so adds it as a transitive dependency.

@dave-r12
Copy link
Collaborator

Shoot, is this from the maven-bundle-plugin?

@BoD
Copy link
Author

BoD commented Jan 14, 2016

@dave-r12 The way I see it, this is intended behavior. The indesirable part is the included .class files in okhttp-url-connection.jar (IMHO).

@JakeWharton
Copy link
Member

OkHttp 3 support is already merged into Picasso master (and Retrofit) and there exists standalone projects on my GitHub for support of all current versions.

@swankjesse
Copy link
Member

Ugh, not sure why okhttp3-urlconnection contains more classes than it’s supposed to. I’ll prepare a fix.

@swankjesse
Copy link
Member

The too-many-class-files fix is here:
#2246

@swankjesse
Copy link
Member

Fixed & released as 3.0.1. Trying to enable OSGi burned us on this one.

@efkan
Copy link

efkan commented Jul 2, 2016

Hello,

I get the same error when I try to use okhttp-3.3.1.jar. Do you have any idea?

Explanation:
I'll try to build an Android app that' been developed by using react-native. At the same time I know that react-native uses the okhttp3 in its NetworkingModule. But I get this error.

Also I tried out okhttp-3.0.1.jar. I get the same error. Therefore I guess a different thing causes the problem and it specific to me.

After a while: I think the problem regarding with both of react-native and I use the okhttp3 library. And because of the same class names a conflict occurs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants