微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

android – Volley 1.1依赖于org.apache.http

据我所知,https://github.com/google/volley/wiki/Migrating-from-Apache-HTTP volley 1.1删除了对org.apache.http的强制依赖.和

“Most apps using HurlStack or Volley#newRequestQueue with
minSdkVersion set to 9 or higher should not need to take any action
other than removing the useLibrary ‘org.apache.http.legacy’ declaration from your build.gradle file if it is present.”

我没有在任何地方使用org.apache.http,但是当我尝试在单元测试中执行Volley.newRequestQueue(context.getApplicationContext())或新的HurlStack()时,我得到:

java.lang.NoClassDefFoundError: org/apache/http/StatusLine

在运行时.检查HurlStack类我看到它继承自BaseHttpStack,它显然仍然依赖于org.apache.http

import org.apache.http.ProtocolVersion;
import org.apache.http.StatusLine;
import org.apache.http.entity.Basichttpentity;
import org.apache.http.message.BasicHeader;
import org.apache.http.message.BasicHttpResponse;
import org.apache.http.message.BasicStatusLine;

所以,我没有得到它,我是否应该包括org.apache.http如果使用带有api级别的凌空> 23或不?

解决方法

如果我将它包含在build.gradle中,测试运行正常:

testImplementation "org.apache.httpcomponents:httpclient:4.5.5"

注意:

这不是关于NoClassDefFoundError的一般性问题,它特别关注Volley在指令(阅读帖子上的链接)说不应该抛出此异常时抛出此异常.

解决方法

在Android Pi(9)设备的Application标签中的AndroidManifest文件中使用以下行
<uses-library
            android:name="org.apache.http.legacy"
            android:required="false" />

原文地址:https://www.jb51.cc/android/314664.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐