2016-06-11 51 views
1

我想用這種粘貼以下代碼PicassoCache,但使用後如:的Android使用畢加索緩存,並得到NoClassDefFoundError的錯誤在我的應用程序

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

回答

0

爲我工作結合

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

可能會有所幫助。

0

嘗試以下組合,它的工作對我來說:

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

希望它會爲你:)

相關問題