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

前端之家收集整理的这篇文章主要介绍了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.f2er.com/android/314664.html

猜你在找的Android相关文章