我正在开发一个项目,该项目使用 Android 中的 Picasso 库具有离线功能。到目前为止,我只是在学习教程。
这是我的gradle:
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 设置:
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 的方式:
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);
}
});
最佳答案
我不完全理解这个问题和这个解决方案。似乎在最近对 OkHttp 库的修订中,包含 OkHttpClient
的包发生了变化。 Picasso 的 2.5.2 版本希望在旧包 com.squareup.okhttp
中找到它。一种解决方案是替换:
compile 'com.squareup.okhttp3:okhttp:3.4.1'
与
compile 'com.squareup.okhttp:okhttp:2.5.0'
可能会有更好的解决方案。这是我找到的唯一一个。
关于android - java.lang.NoClassDefFoundError : Failed resolution of: Lcom/squareup/okhttp/OkHttpClient error when using Picasso offline capability - Android 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39899853/