在Eclipse中导入Picasso和OkHttp [英] Importing Picasso and OkHttp in Eclipse

查看:1149
本文介绍了在Eclipse中导入Picasso和OkHttp的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要公开一些毕加索资源来满足一个相当奇怪的要求。为此,我需要将毕加索作为库项目导入,而不是编译的jar。我创建了一个新的Android项目,并将picasso\picasso\src\main\java(克隆的主控)的内容复制到src文件夹。毕加索使用OkHttp,所以我下载了最新版本的jar(2.3.0),并将其放在毕加索项目的libs文件夹中;将其添加到构建路径;在构建路径中选择该jar订单和导出首选项。最后,我将Picasso项目作为图书馆,并将其包含在主要项目中(也从libs中删除了旧的Picasso jar)。



应用程序首次尝试制作Picasso请求时,我收到以下异常:

  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):com.squareup.picasso.OkHttpDownloader。< init>(OkHttpDownloader.java:55)
04-12 17:04:15.956:E / AndroidRuntime(5436):com.squareup.picasso.OkHttpDownloader。< init>(OkHttpDownloader.java:45)
04-12 17:04 :15.956:E / AndroidRuntime(5436):在com.squareup.picasso.Utils $ OkHttpLoade rCreator.create(Utils.java:424)
04-12 17:04:15.956:E / AndroidRuntime(5436):在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)

指定的类似乎在jar中,但DiskLruCache.java似乎分为9个类文件:

  $ 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

我准备提供额外的信息。任何建议将被高度赞赏。



编辑:



在OkHttp jar中我试图将其导入主要项目以及毕加索jar(最新 - 2.5.2),我也得到了同样的例外。我没有看到任何OkHttp警告,表示与其他线程中所述的不兼容。

解决方案

OkHttp需要 Okio 上班。这是在 GitHub页面上提到的,位于下载按钮下面。导入Okio jar修复了NoClassDefFoundError。以下是我刚刚测试的工作配置:
毕加索:2.5。 2 ; okhttp:2.3.0 ; okio:1.3.0


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.

解决方案

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.

这篇关于在Eclipse中导入Picasso和OkHttp的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆