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

A N*_*iq. 3 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'
}
Run Code Online (Sandbox Code Playgroud)

这是我毕加索的设定:

    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);
Run Code Online (Sandbox Code Playgroud)

这就是我在毕加索中称之为毕加索的方式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);
            }
        });
Run Code Online (Sandbox Code Playgroud)

Bob*_*der 8

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

compile 'com.squareup.okhttp3:okhttp:3.4.1'
Run Code Online (Sandbox Code Playgroud)

compile 'com.squareup.okhttp:okhttp:2.5.0'
Run Code Online (Sandbox Code Playgroud)

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