java – 在Android Studio中使用unirest的问题
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了java – 在Android Studio中使用unirest的问题,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含3509字,纯文字阅读大概需要6分钟。
内容图文
![java – 在Android Studio中使用unirest的问题](/upload/InfoBanner/zyjiaocheng/772/d75c4db5af2e4e8b9799e8af219df9c1.jpg)
我在我的logcat中遇到了一些错误,这些错误导致我的应用程序在尝试执行某些不正确的请求时崩溃.我知道你必须生成一个包含所有依赖项的特殊unirest jar,但是我遇到了maven的问题并没有这样做,而是我在libs文件夹中单独包含了依赖项.我已将问题缩小到下面的这个错误.
logcat的:
java.lang.VerifyError: com/mashape/unirest/http/options/Options
at com.mashape.unirest.http.HttpClientHelper.prepareRequest(HttpClientHelper.java:154)
at com.mashape.unirest.http.HttpClientHelper.request(HttpClientHelper.java:131)
at com.mashape.unirest.request.BaseRequest.asJson(BaseRequest.java:68)
我知道java.lang.verifyerror是由编译时与运行时给出的不同库引起的.但我不知道如何解决这个问题.请帮助,确保我需要的所有依赖项都在下面,因为我之前没有使用过unirest.
的build.gradle:
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile files('libs/unirest-java-1.3.20.jar')
compile files('libs/rebound-0.3.6.jar')
compile files('libs/commons-io-2.4.jar')
compile files('libs/json-20140107.jar')
compile files('libs/httpmime-4.3.5.jar')
compile files('libs/httpclient-4.3.5.jar')
compile files('libs/httpasyncclient-4.0.2.jar')
compile files('libs/httpcore-4.3.2.jar')
compile files('libs/commons-codec-1.6.jar')
compile files('libs/commons-logging-1.1.3.jar')
}
我的libs文件夹是什么样的:
commons-io-2.4.jar
httpcore-4.3.2.jar
httpclient-4.3.5.jar
commons-logging-1.1.3.jar
json-20140107.jar
rebound-0.3.6.jar
unirest-java-1.3.20.jar
commons-codec-1.6.jar
httpmime-4.3.5.jar
httpasyncclient-4.0.2.jar
还包括在build.gradle中,因为我在尝试构建gradle文件时遇到重复的文件错误:
packagingOptions {
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/NOTICE'
exclude 'META-INF/LICENSE'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
}
解决方法:
我知道你提出这个问题已经有一段时间了.我认为Android会覆盖位于org.apache.http中的常见类.你不能自己覆盖它们.尝试将下载的软件包重新定位到另一个位置,例如surrogate.org.apache.http,以便正确使用它们.
从https://hc.apache.org/httpcomponents-client-4.3.x/android-port.html开始:
Google Android 1.0 was released with a pre-BETA snapshot of Apache HttpClient. To coincide with the first Android release Apache HttpClient 4.0 APIs had to be frozen prematurely, while many of interfaces and internal structures were still not fully worked out. As Apache HttpClient 4.0 was maturing the project was expecting Google to incorporate the latest code improvements into their code tree. Unfortunately it did not happen. Version of Apache HttpClient shipped with Android has effectively become a fork. Eventually Google decided to discontinue further development of their fork while refusing to upgrade to the stock version of Apache HttpClient citing compatibility concerns as a reason for such decision. As a result those Android developers who would like to continue using Apache HttpClient APIs on Android cannot take advantage of newer features, performance improvements and bug fixes.
如果继续阅读,您会发现以下内容:
Some of the implementation classes had to be copied (or shaded) with different names in order to avoid conflicts with the older versions of the same classes included in the Android runtime. One can increase compatibility of with the stock version of HttpClient by avoiding ‘org.apache.http.**.*HC4’ classes.
使用
dependencies {
compile group: 'org.apache.httpcomponents' , name: 'httpclient-android' , version: '4.3.5.1'
}
包括httpcomponents.
如果您不想手动重定位,则可能必须使用shadowJar插件重定位依赖项.
编辑:
我找到了this很棒的教程,对我有用.甚至以为我会建议使用AndroidAsync或Volley来建立与网络服务器的连接.
内容总结
以上是互联网集市为您收集整理的java – 在Android Studio中使用unirest的问题全部内容,希望文章能够帮你解决java – 在Android Studio中使用unirest的问题所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。