我仍在学习 Dagger 2 并尝试使用它创建一个简单的应用程序。我无法让 Picasso 工作,因为我在日志中看不到任何错误。这是我的代码AppModule.java@Module(includes = {AndroidInjectionModule.class, NetworkModule.class, ViewModelModule.class})public class AppModule { ... @Provides @AppScope Picasso picasso(App app, OkHttp3Downloader okHttp3Downloader) { return new Picasso.Builder(app.getApplicationContext()) .downloader(okHttp3Downloader) .loggingEnabled(true) .build(); } ...}NetworkModule.java这是 OkHttp3Downloader 依赖项所在的位置。@Modulepublic class NetworkModule { @Provides @AppScope HttpLoggingInterceptor loggingInterceptor() { HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor(message -> Timber.i(message)); interceptor.setLevel(HttpLoggingInterceptor.Level.BODY); return interceptor; } @Provides @AppScope public File file(App app) { return new File(app.getApplicationContext().getCacheDir(), "okhttp_cache"); } @Provides @AppScope Cache cache(File file) { return new Cache(file, 10 * 1000 * 1000); } @Provides @AppScope OkHttpClient okHttpClient(HttpLoggingInterceptor loggingInterceptor, Cache cache) { return new OkHttpClient.Builder() .addInterceptor(loggingInterceptor) .cache(cache) .build(); } @Provides @AppScope OkHttp3Downloader okHttp3Downloader(OkHttpClient okHttpClient) { return new OkHttp3Downloader(okHttpClient); } }
1 回答
largeQ
TA贡献2039条经验 获得超7个赞
我终于弄明白了。OkHttp3Downloader 存在问题,因为当我删除它时,毕加索可以成功加载图像。然后我尝试导入 com.squareup.picasso.OkHttp3Downloader 而不是 com.jakewharton.picasso.OkHttp3Downloader,现在它可以工作了。我真的不知道为什么我不能使用 jakewharton 的,但两者之间有什么区别。
添加回答
举报
0/150
提交
取消