android – 对于OkHttpClient的NoClassDefFoundError

前端之家收集整理的这篇文章主要介绍了android – 对于OkHttpClient的NoClassDefFoundError前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
在gradle中添加了facebook依赖关系后,我得到这个运行时错误
compile 'com.facebook.android:facebook-android-sdk:4.6.0'

请注意,我也使用okhttp:

compile 'com.squareup.okhttp:okhttp:2.5.0'

错误日志是:

E/AndroidRuntime: FATAL EXCEPTION: Thread-109754
     Process: com.venkat.project,PID: 4453
            java.lang.NoClassDefFoundError: com.squareup.okhttp.internal.Util
            at com.squareup.okhttp.OkHttpClient.<clinit>(OkHttpClient.java:57)
            at com.venkat.project.http.MyHTTPThread.run(MyHTTPThread.java:127)
            at com.venkat.project.http.MyHTTPThread.run(MyHTTPThread.java:61)
            at java.lang.Thread.run(Thread.java:841)
02-23 18:11:02.729 4453-4573/com.venkat.project I/dalvikvm: Rejecting re-init on prevIoUsly-Failed class Lcom/squareup/okhttp/OkHttpClient; v=0x0

注意:我在三星手机4.4上得到这个错误,但是在模拟器和在moto g 5.0上它是有效的.

解决方法

你得到了
java.lang.NoClassDefFoundError: com.squareup.okhttp.internal.Util
        at com.squareup.okhttp.OkHttpClient.<clinit>(OkHttpClient.java:57)
        at com.venkat.project.http.MyHTTPThread.run(MyHTTPThread.java:127)
        at com.venkat.project.http.MyHTTPThread.run(MyHTTPThread.java:61)

OkHttpClient的NoClassDefFoundError

public class NoClassDefFoundError extends LinkageError

Thrown if the Java Virtual Machine or a ClassLoader instance tries to
load in the definition of a class (as part of a normal method call or
as part of creating a new instance using the new expression) and no
definition of the class could be found.

报价从NoClassDefFoundError

你应该使用

compile 'com.facebook.android:facebook-android-sdk:4.10.0'

之后,您可以得到非零退出值2的错误

然后

defaultConfig {
    ...
    minSdkVersion 14 //lower than 14 doesn't support multidex
    targetSdkVersion //Yours

    // Enabling multidex support.
    multiDexEnabled true
}

dependencies {
 compile 'com.android.support:multidex:1.0.0'
}

>添加multiDexEnabled true
>调用编译’com.android.support:multidex:1.0.0’//或1.0.1

OkHttp perseveres when the network is troublesome: it will silently
recover from common connection problems. If your service has multiple
IP addresses OkHttp will attempt alternate addresses if the first
connect fails. This is necessary for IPv4+IPv6 and for services hosted
in redundant data centers.

您可以致电最新版本

compile 'com.squareup.okhttp3:okhttp:3.2.0'

最后

compile 'com.squareup.okhttp3:okhttp:3.0.1'
or // compile 'com.squareup.okhttp:okhttp:2.5.0'
compile 'com.facebook.android:facebook-android-sdk:4.10.0'

然后

清洁和重建&同步您的项目希望这可以帮助 .

原文链接:https://www.f2er.com/android/311519.html

猜你在找的Android相关文章