前言

  • android9.0坑:Failed resolution of: Lorg/apache/http/message/BasicNameValuePair

问题

1
2
3
4
5
6
7
8
9
java.lang.NoClassDefFoundError: Failed resolution of: Lorg/apache/http/message/BasicNameValuePair;
    at id.mania.pinja.obtaindata.ObtainUploadPackageDataTask.onSetup(ObtainUploadPackageDataTask.java:53)
    at id.mania.pinja.network.engine.OkHttpEngine.setupHttpTask(OkHttpEngine.java:182)
    at id.mania.pinja.network.engine.OkHttpEngine.executeHttpTask(OkHttpEngine.java:352)
    at id.mania.pinja.network.engine.OkHttpEngine.access$000(OkHttpEngine.java:35)
    at id.mania.pinja.network.engine.OkHttpEngine$TaskRunnable.run(OkHttpEngine.java:653)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
    at java.lang.Thread.run(Thread.java:764)
  • 出现此问题主要是 apache 的 http 库在android 9.0删除导致的,出现此问题应该是使用了 apache 的http库。

解决

我是在application加上

1
2
3
<uses-library
      android:name="org.apache.http.legacy"
      android:required="false" />

总结

  • 最后建议尽量不要再使用httpClient来访问网络,替换成HttpURLConnection或者OKHttp。