android - java.lang.NoClassDefFoundError : Failed resolution of: Lcom/squareup/okhttp/OkHttpClient error when using Picasso offline capability - Android 错误

标签 android firebase picasso okhttp

我正在开发一个项目,该项目使用 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/

相关文章:

javascript - AngularJS 无法在解析函数中从服务获取身份验证对象

Android 与 Picasso 共享元素

Android:带有 GridLayoutManager 的 RecyclerView 中的 Picasso 图像

swift - 我将如何使用一系列信息创建地理围栏?

android - Firebase - 允许多个用户使用电子邮件,如何获得顶级电子邮件

android - 从 url 获取图像并在 ImageView 中显示时调整图像大小

android - 即使有 Activity 客户端也会调用 Service.onUnbind() 吗?

Android Studio 创建数据库和架构的正确方法

android - 在 EditText 之间自动传递焦点

java - 适用于 Android 的 Google map - 多段线崩溃应用