I have to download an image from a URL which requires some headers ( username,password) along with the request. So i am doing that using the code given here. But calling this function gives the error
java.lang.NoClassDefFoundError: com.squareup.okhttp.OkHttpClient
at com.squareup.picasso.OkHttpDownloader.<init>(OkHttpDownloader.java:72)
I am using Picasso 2.3.3 and okhttp-urlconnection-2.0.0-RC2 libraries The issue has been raised in this post also but changing to 2.3.2 doesnt work.
Do you have OkHttp included in your project? If not, the problem is that you're using the OkHttpDownloader. You can include the OkHttp library in your project or just UrlConnectionDownloader like below.
This was the result I ended up with.
public static Picasso getImageLoader(Context ctx) {
Picasso.Builder builder = new Picasso.Builder(ctx);
builder.downloader(new UrlConnectionDownloader(ctx) {
@Override
protected HttpURLConnection openConnection(Uri uri) throws IOException {
HttpURLConnection connection = super.openConnection(uri);
connection.setRequestProperty("X-HEADER", "VAL");
return connection;
}
});
return builder.build();
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With