问题描述
在 gradle 中添加 facebook 依赖项后,我收到此运行时错误:
编译 'com.facebook.android:facebook-android-sdk:4.6.0'
请注意,我也在使用 okhttp:
编译 'com.squareup.okhttp:okhttp:2.5.0'
和错误日志是:
E/AndroidRuntime:致命异常:Thread-109754进程:com.venkat.project,PID:4453java.lang.NoClassDefFoundError: com.squareup.okhttp.internal.Util在 com.squareup.okhttp.OkHttpClient.<clinit>(OkHttpClient.java:57)在 com.venkat.project.http.MyHTTPThread.run(MyHTTPThread.java:127)在 com.venkat.project.http.MyHTTPThread.run(MyHTTPThread.java:61)在 java.lang.Thread.run(Thread.java:841)02-23 18:11:02.729 4453-4573/com.venkat.project I/dalvikvm:拒绝在先前失败的类 Lcom/squareup/okhttp/OkHttpClient 上重新初始化;v=0x0
注意:我在 Samsung mobile 4.4 上遇到此错误,但在模拟器和 moto g 5.0
上它可以工作.
你正在得到
java.lang.NoClassDefFoundError: com.squareup.okhttp.internal.Util在 com.squareup.okhttp.OkHttpClient.<clinit>(OkHttpClient.java:57)在 com.venkat.project.http.MyHTTPThread.run(MyHTTPThread.java:127)在 com.venkat.project.http.MyHTTPThread.run(MyHTTPThread.java:61)
OkHttpClient 的 NoClassDefFoundError
公共类 NoClassDefFoundError 扩展了 LinkageError
如果 Java 虚拟机或 ClassLoader 实例试图在类的定义中加载(作为正常方法调用的一部分或作为使用 new 表达式创建新实例的一部分)并且没有可以找到类的定义.
你应该使用
编译'com.facebook.android:facebook-android-sdk:4.10.0'
之后你会得到这个错误以非零退出值 2 结束
然后
defaultConfig {...minSdkVersion 14//低于14不支持multidextargetSdkVersion//你的//启用多索引支持.multiDexEnabled true}依赖{实现 'com.android.support:multidex:1.0.0'}
调用
implementation'com.android.support:multidex:1.0.2'
网络有问题时OkHttp坚持:它会默默地从常见的连接问题中恢复.如果您的服务有多个IP 地址 OkHttp 将尝试备用地址,如果第一个连接失败.这对于 IPv4+IPv6 和托管服务是必需的在冗余数据中心.
您可以调用最新版本
实现'com.squareup.okhttp3:okhttp:3.2.0'
然后
清理和重新构建 &同步
您的项目.希望这会有所帮助.
After adding the facebook dependency in gradle I'm getting this runtime error:
compile 'com.facebook.android:facebook-android-sdk:4.6.0'
Please notice that I'm also using okhttp:
compile 'com.squareup.okhttp:okhttp:2.5.0'
and error log is:
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
Note: I'm getting this error on Samsung mobile 4.4 but on the emulator and on moto g 5.0
it works.
You are getting
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)
NoClassDefFoundError for OkHttpClient
public class NoClassDefFoundError extends LinkageError
Quote from NoClassDefFoundError
You should use
compile 'com.facebook.android:facebook-android-sdk:4.10.0'
After that you can get this error finished with non-zero exit value 2
Then
defaultConfig {
...
minSdkVersion 14 //lower than 14 doesn't support multidex
targetSdkVersion //Yours
// Enabling multidex support.
multiDexEnabled true
}
dependencies {
implementation 'com.android.support:multidex:1.0.0'
}
Call
implementation'com.android.support:multidex:1.0.2'
You can call latest version
implementation'com.squareup.okhttp3:okhttp:3.2.0'
Then
Clean and Re-Build & Sync
Your Project . Hope this helps .
这篇关于OkHttpClient 的 NoClassDefFoundError的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!