2016-10-06 2 views
1

AndroidのPicasaライブラリを使用してオフライン機能を持つプロジェクトに取り組んでいます。これまではチュートリアルに従っています。java.lang.NoClassDefFoundError:Picasaのオフライン機能を使用しているときにLcom/squareup/okhttp/OkHttpClientエラーが発生しました - Android

これは私のGradleです:

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でピカソを呼び出す方法です:

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.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); 
      } 
     }); 

答えて

6

私は「ドン問題とこの解決策を完全に理解していない。最近のOkHttpライブラリの改訂では、OkHttpClientを含むパッケージが変更されたようです。ピカソの2.5.2バージョンは古いパッケージのcom.squareup.okhttpで見つかると予想しています。よりよい解決策があるかもしれません

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

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

に:一つの解決策は、交換することです。これは私が見つけた唯一のものです。

+0

おかげで、魅力のように働いた:) –

+0

ニース私の日の仲間を救う –

+0

あなたは私の日を救う!!!! –

2

あなたがokhttp3を維持したい場合は、あなたがJake Wharton's solutionを使用することができます。

のGradleに追加:

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

はして初期化します。

OkHttpClient client = // ... 
Picasso picasso = new Picasso.Builder(context) 
    .downloader(new OkHttp3Downloader(client)) 
    .build() 
関連する問題