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" />

相关文章

Android 如何解决dialog弹出时无法捕捉Activity的back事件 在...
Android实现自定义带文字和图片的Button 在Android开发中经常...
Android 关于长按back键退出应用程序的实现最近在做一个Andr...
android自带的时间选择器只能精确到分,但是对于某些应用要求...