本文介绍了对于OkHttpClient,NoClassDefFoundError的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  

解决方案

你正在得到

  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 





您应该使用

  compile'c​​om.facebook.android:facebook-android-sdk:4.10.0' 

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



然后

 code> defaultConfig {
...
minSdkVersion 14 //低于14不支持multidex
targetSdkVersion //您的

//启用multidex支持。
multiDexEnabled true
}

依赖关系{
compile'c​​om.android.support:multidex:1.0.0'
}




  1. 添加 multiDexEnabled true


  2. code> compile'c​​om.android.support:multidex:1.0.0' //或1.0.1




您可以调用最新版本



  compile'c​​om.squareup.okhttp3:okhttp:3.2.0'

最后

  compile'c​​om .squareup.okhttp3:okhttp:3.0.1'
或//编译'com.squareup.okhttp:okhttp:2.5.0'
compile'c​​om.facebook.android:facebook-android-sdk: 4.10.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 {
 compile 'com.android.support:multidex:1.0.0'
}
  1. Add multiDexEnabled true

  2. Call compile 'com.android.support:multidex:1.0.0' // or 1.0.1

You can call latest version

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

Finally

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'

Then

Clean and Re-Build & Sync Your Project . Hope this helps .

这篇关于对于OkHttpClient,NoClassDefFoundError的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-20 12:31