question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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?

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:13 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
efkancommented, Oct 18, 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.

1reaction
dave-r12commented, Jan 14, 2016

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

Read more comments on GitHub >

github_iconTop Results From Across the Web

android - not able to import com.squareup.okhttp.OkHttpClient
Gradle should have a line like this implementation 'com.squareup.okhttp3:okhttp:3.0.1'. and this is how you import it import okhttp3.OkHttpClient;.
Read more >
Starting an application on Android - Reader SDK - Questions
It looks like your app-level build.gradle isn't looking in the Square repository for the Reader SDK artifact. ERROR: Failed to resolve: com.
Read more >
Add build dependencies - Android Developers
Learn how to add build dependencies using the Gradle build system in Android ... Caution: When specifying dependencies, you should not use dynamic...
Read more >
Spring Boot Gradle Plugin Reference Guide
When using Gradle's bom support, you cannot use the properties from spring-boot-dependencies to control the versions of the dependencies ...
Read more >
How to use Gradle api vs. implementation dependencies with ...
This configuration will get used to generate both compile and ... on explicitly e.g. can't use Library C in Application as it's not...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found