Importing Picasso and OkHttp in Eclipse

匿名 (未验证) 提交于 2019-12-03 10:24:21

问题:

I need to expose some Picasso resources to satisfy a rather strange request. For this I need to import Picasso as a library project instead of a compiled jar. I've created a new Android Project and copied the contents of picasso\picasso\src\main\java (cloned master) to the src folder. Picasso uses OkHttp so I downloaded the latest release jar (2.3.0) and put it in the libs folder of the Picasso project; added it to the build path; selected the jar in the build path "Order and Export" preferences. Finally, I made the Picasso project a library and included it in the main project (also removed the old Picasso jar from libs).

The first time the application tries to make a Picasso request I get the following exception:

04-12 17:04:15.956: E/AndroidRuntime(5436): java.lang.NoClassDefFoundError: com.squareup.okhttp.internal.DiskLruCache$4 04-12 17:04:15.956: E/AndroidRuntime(5436):     at com.squareup.okhttp.internal.DiskLruCache.<clinit>(DiskLruCache.java:810) 04-12 17:04:15.956: E/AndroidRuntime(5436):     at com.squareup.okhttp.Cache.<init>(Cache.java:168) 04-12 17:04:15.956: E/AndroidRuntime(5436):     at com.squareup.picasso.OkHttpDownloader.<init>(OkHttpDownloader.java:77) 04-12 17:04:15.956: E/AndroidRuntime(5436):     at com.squareup.picasso.OkHttpDownloader.<init>(OkHttpDownloader.java:55) 04-12 17:04:15.956: E/AndroidRuntime(5436):     at com.squareup.picasso.OkHttpDownloader.<init>(OkHttpDownloader.java:45) 04-12 17:04:15.956: E/AndroidRuntime(5436):     at com.squareup.picasso.Utils$OkHttpLoaderCreator.create(Utils.java:424) 04-12 17:04:15.956: E/AndroidRuntime(5436):     at com.squareup.picasso.Utils.createDefaultDownloader(Utils.java:250) 04-12 17:04:15.956: E/AndroidRuntime(5436):     at com.squareup.picasso.Picasso$Builder.build(Picasso.java:832) 04-12 17:04:15.956: E/AndroidRuntime(5436):     at com.squareup.picasso.Picasso.with(Picasso.java:662) 

The specified class seems to be in the jar but DiskLruCache.java seems broken into a total of 9 class files:

$ ls DiskLruCache* DiskLruCache$1.class  DiskLruCache$4.class         DiskLruCache$Entry.class DiskLruCache$2.class  DiskLruCache$Editor$1.class  DiskLruCache$Snapshot.class DiskLruCache$3.class  DiskLruCache$Editor.class    DiskLruCache.class 

I'm ready to provide additional info. Any advice would be highly appreciated.

Edit:

The problem seems to be in the OkHttp jar. I've tried to import it in the main project along with the Picasso jar (latest - 2.5.2) and I get the same exception. I do not see any OkHttp warnings, indicating incompatibility as stated in some other threads.

回答1:

OkHttp requires Okio to work. This is mentioned on the GitHub page, right under the download button. Importing the Okio jar fixed the NoClassDefFoundError. Here's a working configuration that I just tested: picasso:2.5.2; okhttp:2.3.0; okio:1.3.0.



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!