java.lang.NoClassDefFoundError:使用Picasso离线功能时失败的解决方案:Lcom / squareup / okhttp / OkHttpClient错误 - Android

时间:2016-10-06 15:19:41

标签: android firebase picasso okhttp3

我正在开发一个使用Android中的Picasso库具有离线功能的项目。到目前为止,我只是按照教程。

这是我的傻瓜:

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.4.0'
compile 'com.android.support:recyclerview-v7:23.4.0'
compile 'com.android.support:cardview-v7:23.4.0'
compile 'com.android.support:design:23.4.0'
compile 'com.google.firebase:firebase-database:9.0.2'
compile 'com.google.firebase:firebase-core:9.0.2'
compile 'com.google.firebase:firebase-auth:9.0.2'
compile 'com.firebase:firebase-client-android:2.3.1'
compile 'com.google.firebase:firebase-storage:9.0.2'
compile 'com.google.firebase:firebase-database:9.0.2'
compile 'com.firebaseui:firebase-ui-database:0.4.0'
compile 'com.squareup.picasso:picasso:2.5.2'
compile 'com.squareup.okhttp3:okhttp:3.4.1'
}

这是我毕加索的设定:

    Picasso.Builder builder = new Picasso.Builder(this);
    builder.downloader(new OkHttpDownloader(this,Integer.MAX_VALUE)); //always give me the error to this line
    Picasso built = builder.build();
    built.setIndicatorsEnabled(false);
    built.setLoggingEnabled(true);
    Picasso.setSingletonInstance(built);

这就是我在actvity.java中称毕加索的方式:

Picasso.with(this.getApplicationContext()).load(stringUriProfile).networkPolicy(NetworkPolicy.OFFLINE).into(mUriImageProfile, new Callback() {
            @Override
            public void onSuccess() {
                //the function fires whenever the picasso doesnt find picture from offline way
            }

            @Override
            public void onError() {
                Context ctx = getApplicationContext();
                Picasso.with(ctx).load(stringUriProfile).into(mUriImageProfile);
            }
        });

2 个答案:

答案 0 :(得分:8)

我不完全理解这个问题和这个解决方案。似乎在最近对OkHttp库的修订中,包含OkHttpClient的包已更改。毕加索的2.5.2版本希望在旧的包com.squareup.okhttp中找到它。一种解决方案是替换:

compile 'com.squareup.okhttp3:okhttp:3.4.1'

compile 'com.squareup.okhttp:okhttp:2.5.0'

可能有更好的解决方案。这是我找到的唯一一个。

答案 1 :(得分:4)

如果您想保留self,可以使用Jake Wharton's solution

添加到gradle:

okhttp3

初始化:

 compile 'com.jakewharton.picasso:picasso2-okhttp3-downloader:1.1.0'