NoClassDefFoundError for OkHttpClient
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.
The latest version of Piccasso use an older version of Okhttp, you need to use a new dependency
compile 'com.squareup.okhttp3:okhttp:3.2.0'
compile 'com.squareup.picasso:picasso:2.5.2'
compile 'com.jakewharton.picasso:picasso2-okhttp3-downloader:1.0.2'
Example:
File httpCacheDirectory = new File(getCacheDir(), "picasso-cache");
Cache cache = new Cache(httpCacheDirectory, 10 * 1024 * 1024);
OkHttpClient.Builder clientBuilder = new OkHttpClient.Builder().cache(cache);
Picasso.Builder picassoBuilder = new Picasso.Builder(getApplicationContext());
picassoBuilder.downloader(new OkHttp3Downloader(clientBuilder.build()));
Picasso picasso = picassoBuilder.build();
try {
Picasso.setSingletonInstance(picasso);
} catch (IllegalStateException ignored) {
Log.e(LOG_TAG, "Picasso instance already used");
}
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
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'
}
Add multiDexEnabled true
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 .