【问题标题】:Android use Picasso Cache and get NoClassDefFoundError ErrorAndroid 使用 Picasso Cache 并得到 NoClassDefFoundError 错误
【发布时间】:2016-06-12 05:22:23
【问题描述】:

在我的应用程序中,我想将下面粘贴的代码用作 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

毕加索缓存:

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;
    }
}

我的毕业生:

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'
}

【问题讨论】:

    标签: android


    【解决方案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'
    

    效果很好,但here 一些答案说

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

    可能有帮助。

    【讨论】:

      【解决方案2】:

      尝试以下组合,它对我有用:

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

      希望它对你有用:)

      【讨论】:

        猜你喜欢
        • 2013-06-07
        • 1970-01-01
        • 2014-08-24
        • 1970-01-01
        • 1970-01-01
        • 2017-04-20
        • 2020-07-04
        • 2010-12-09
        • 1970-01-01
        相关资源
        最近更新 更多