java.lang.NoClassDefFoundError: okhttp3.OkHttpClient

Android 码拜 8年前 (2017-04-30) 4611次浏览
Android 5.X以下的操作系统,就会出现这个问题,5.X以上一切运行正常!
求高手解答

05-08 19:14:15.386 28103-28103/com.pd.user E/AndroidRuntime: FATAL EXCEPTION: main
                                                             Process: com.pd.user, PID: 28103
                                                             java.lang.NoClassDefFoundErrorokhttp3.OkHttpClient
                                                                 at com.pd.user.net.OkHttpClientManager.<init>(OkHttpClientManager.java:50)
                                                                 at com.pd.user.net.OkHttpClientManager.<init>(OkHttpClientManager.java:40)
                                                                 at com.pd.user.net.OkHttpClientManager$SingLetonHolder.<clinit>(OkHttpClientManager.java:72)
                                                                 at com.pd.user.net.OkHttpClientManager.getInstance(OkHttpClientManager.java:77)
                                                                 at com.pd.user.activity.MainActivity.initData(MainActivity.java:196)
                                                                 at com.pd.user.activity.MainActivity.onCreate(MainActivity.java:75)
                                                                 at android.app.Activity.performCreate(Activity.java:5312)
                                                                 at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1111)
                                                                 at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2552)
                                                                 at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2653)
                                                                 at android.app.ActivityThread.access$800(ActivityThread.java:156)
                                                                 at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1355)
                                                                 at android.os.Handler.dispatchMessage(Handler.java:102)
                                                                 at android.os.Looper.loop(Looper.java:157)
                                                                 at android.app.ActivityThread.main(ActivityThread.java:5883)
                                                                 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:871)
                                                                 at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:687)
                                                                 at dalvik.system.NativeStart.main(Native Method)
解决方案

5

Android系统从哪个版本开始,不记得了,不是4点几就是5.0,内部网络开始使用okhttp,而之前使用的是httpurlconnection和httpclient,所以以前的版本不能直接使用okhttp,要导入jar包

5

包冲突了,存在两个okhttp包,不知道应该调用哪一个包的方法就会出现这个问题

10

引用:
Quote: 引用:

的确很奇怪,把那个jar包删了用  compile “com.squareup.okhttp3:okhttp:3.2.0″ 这样导看看?

java.lang.NoClassDefFoundError: okhttp3.OkHttpClient
项目中的这个2个moudle 用到了 Okhttp3
然后本人在 oss-android-sdk 依赖中加入了
compile “com.squareup.okhttp3:okhttp:3.2.0”
compile “com.squareup.okio:okio:1.6.0”
然后app中添加了
compile project(“:oss-android-sdk”)
但在5.X以下还是报错了

对啊,你下面的已经compile “com.squareup.okhttp3:okhttp:3.2.0″,然后上面的app又导入下面这个,然后又导入了okhttp3.2的jar包,不就冲突了吗?


CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明java.lang.NoClassDefFoundError: okhttp3.OkHttpClient
喜欢 (0)
[1034331897@qq.com]
分享 (0)