NoClassDefFoundError for OkHttpClient

前端 未结 4 2075
没有蜡笔的小新
没有蜡笔的小新 2020-12-01 17:16

After adding the facebook dependency in gradle I\'m getting this runtime error:

     compile \'com.facebook.android:facebook-android-sdk:4.6.0\'
4条回答
  •  自闭症患者
    2020-12-01 17:20

    You are getting

           java.lang.NoClassDefFoundError: com.squareup.okhttp.internal.Util
            at com.squareup.okhttp.OkHttpClient.(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
    

    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.

    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'
    }
    
    1. Add multiDexEnabled true

    2. Call implementation'com.android.support:multidex:1.0.2'

    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.

    You can call latest version

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

    Then

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

提交回复
热议问题