Android使用Picasso Cache并获取NoClassDefFoundError错误(Android use Picasso Cache and get NoClassDefFoundErr

编程入门 行业动态 更新时间:2024-10-08 02:26:19
Android使用Picasso Cache并获取NoClassDefFoundError错误(Android use Picasso Cache and get NoClassDefFoundError Error)

在我的应用程序中,我想使用下面的粘贴代码作为PicassoCache,但在使用后如:

PicassoCache.getPicassoInstance(context) .load(list.get(position).getStoreImage()) .placeholder(R.drawable.ic_messages) .into(holder.store_avatar);

我得到这个错误:

Could not find class 'com.squareup.okhttp.CacheControl$Builder', referenced from method com.squareup.picasso.OkHttpDownloader.load 06-12 01:13:17.484 6246-6246/ir.pishguy.signalpresentationproject E/AndroidRuntime: FATAL EXCEPTION: main java.lang.NoClassDefFoundError: com.squareup.okhttp.OkHttpClient

PicassoCache:

import com.squareup.picasso.Downloader; import com.squareup.picasso.OkHttpDownloader; import com.squareup.picasso.Picasso; public class PicassoCache { private static Picasso picassoInstance = null; private PicassoCache(Context context) { Downloader downloader = new OkHttpDownloader(context, Integer.MAX_VALUE); Picasso.Builder builder = new Picasso.Builder(context); builder.downloader(downloader); picassoInstance = builder.build(); } public static Picasso getPicassoInstance(Context context) { if (picassoInstance == null) { new PicassoCache(context); return picassoInstance; } return picassoInstance; } }

我的gradle:

apply plugin: 'android-sdk-manager' apply plugin: 'com.android.application' apply plugin: 'android-command' apply plugin: 'realm-android' android { compileSdkVersion 23 buildToolsVersion "23.0.2" defaultConfig { applicationId "ir.pishguy.signalpresentationproject" minSdkVersion 14 targetSdkVersion 22 versionCode 1 versionName "1.0" multiDexEnabled true } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } command { events 2000 } lintOptions { disable 'InvalidPackage' } packagingOptions { exclude 'META-INF/services/javax.annotation.processing.Processor' exclude 'META-INF/NOTICE' exclude 'META-INF/LICENSE' } } ext { supportLibVersion = '23.4.0' } dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) testCompile 'junit:junit:4.12' compile "com.android.support:appcompat-v7:${supportLibVersion}" compile "com.android.support:support-v4:${supportLibVersion}" compile "com.android.support:design:${supportLibVersion}" compile 'com.squareup.picasso:picasso:2.5.2' compile('io.socket:socket.io-client:0.7.0') { // excluding org.json which is provided by Android exclude group: "org.json", module: "json" } compile ('com.squareup.retrofit2:retrofit:2.0.2'){ exclude module:'okhttp' } compile 'com.squareup.retrofit2:converter-gson:2.0.0-beta4' compile 'com.squareup.okhttp3:okhttp:3.3.1' compile 'com.google.code.gson:gson:2.6.2' compile 'com.github.devlight.navigationtabbar:library:+' compile 'com.android.support:recyclerview-v7:23.3.0' compile "de.hdodenhof:circleimageview:2.0.0" compile 'com.joanzapata.iconify:android-iconify-fontawesome:2.2.2' compile "com.balysv:material-ripple:1.0.2" compile 'com.github.traex.rippleeffect:library:1.3' compile 'com.github.chyrta:AndroidOnboarder:+' compile 'com.jakewharton:butterknife:7.0.1' compile 'com.android.support:multidex:1.0.1' }

in my application i want to use this below pasted code as PicassoCache, but after use that such as :

PicassoCache.getPicassoInstance(context) .load(list.get(position).getStoreImage()) .placeholder(R.drawable.ic_messages) .into(holder.store_avatar);

i get this error:

Could not find class 'com.squareup.okhttp.CacheControl$Builder', referenced from method com.squareup.picasso.OkHttpDownloader.load 06-12 01:13:17.484 6246-6246/ir.pishguy.signalpresentationproject E/AndroidRuntime: FATAL EXCEPTION: main java.lang.NoClassDefFoundError: com.squareup.okhttp.OkHttpClient

PicassoCache:

import com.squareup.picasso.Downloader; import com.squareup.picasso.OkHttpDownloader; import com.squareup.picasso.Picasso; public class PicassoCache { private static Picasso picassoInstance = null; private PicassoCache(Context context) { Downloader downloader = new OkHttpDownloader(context, Integer.MAX_VALUE); Picasso.Builder builder = new Picasso.Builder(context); builder.downloader(downloader); picassoInstance = builder.build(); } public static Picasso getPicassoInstance(Context context) { if (picassoInstance == null) { new PicassoCache(context); return picassoInstance; } return picassoInstance; } }

My gradle:

apply plugin: 'android-sdk-manager' apply plugin: 'com.android.application' apply plugin: 'android-command' apply plugin: 'realm-android' android { compileSdkVersion 23 buildToolsVersion "23.0.2" defaultConfig { applicationId "ir.pishguy.signalpresentationproject" minSdkVersion 14 targetSdkVersion 22 versionCode 1 versionName "1.0" multiDexEnabled true } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } command { events 2000 } lintOptions { disable 'InvalidPackage' } packagingOptions { exclude 'META-INF/services/javax.annotation.processing.Processor' exclude 'META-INF/NOTICE' exclude 'META-INF/LICENSE' } } ext { supportLibVersion = '23.4.0' } dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) testCompile 'junit:junit:4.12' compile "com.android.support:appcompat-v7:${supportLibVersion}" compile "com.android.support:support-v4:${supportLibVersion}" compile "com.android.support:design:${supportLibVersion}" compile 'com.squareup.picasso:picasso:2.5.2' compile('io.socket:socket.io-client:0.7.0') { // excluding org.json which is provided by Android exclude group: "org.json", module: "json" } compile ('com.squareup.retrofit2:retrofit:2.0.2'){ exclude module:'okhttp' } compile 'com.squareup.retrofit2:converter-gson:2.0.0-beta4' compile 'com.squareup.okhttp3:okhttp:3.3.1' compile 'com.google.code.gson:gson:2.6.2' compile 'com.github.devlight.navigationtabbar:library:+' compile 'com.android.support:recyclerview-v7:23.3.0' compile "de.hdodenhof:circleimageview:2.0.0" compile 'com.joanzapata.iconify:android-iconify-fontawesome:2.2.2' compile "com.balysv:material-ripple:1.0.2" compile 'com.github.traex.rippleeffect:library:1.3' compile 'com.github.chyrta:AndroidOnboarder:+' compile 'com.jakewharton:butterknife:7.0.1' compile 'com.android.support:multidex:1.0.1' }

最满意答案

对我来说组合

// Retrofit compile('com.squareup.retrofit2:retrofit:2.0.2') { exclude module: 'okhttp' } compile 'com.squareup.retrofit2:converter-gson:2.0.2' compile 'com.squareup.okhttp3:okhttp:3.2.0' // Picasso compile 'com.squareup.picasso:picasso:2.5.2'

运作良好,但这里有一些答案说

compile 'com.squareup.okhttp:okhttp-urlconnection:x.x.x'

可能有帮助。

For me combination

// Retrofit compile('com.squareup.retrofit2:retrofit:2.0.2') { exclude module: 'okhttp' } compile 'com.squareup.retrofit2:converter-gson:2.0.2' compile 'com.squareup.okhttp3:okhttp:3.2.0' // Picasso compile 'com.squareup.picasso:picasso:2.5.2'

works well, but here some answers said that

compile 'com.squareup.okhttp:okhttp-urlconnection:x.x.x'

may help.

更多推荐

本文发布于:2023-07-30 13:58:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1338791.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:错误   Picasso   Android   Cache   Error

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!