Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Volley 1.1 dependency on org.apache.http

as I understand from here https://github.com/google/volley/wiki/Migrating-from-Apache-HTTP volley 1.1 dropped mandatory dependency on org.apache.http. And

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

I don't use org.apache.http anywhere but when I try to do Volley.newRequestQueue(context.getApplicationContext()) or new HurlStack() on a unit test I get:

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

during runtime. Checking the HurlStack class I see it inherits from BaseHttpStack which clearly still depends on 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;

So, I didn't get it, am I supposed to include org.apache.http if using volley with api level > 23 or not ?

Workaround:

If I include this to build.gradle the tests run fine:

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

Note:

This is not a generic question about NoClassDefFoundError, it regards specifically to Volley throwing this exception when the instructions (read link on the post) says it shouldn't.

like image 674
Gus Avatar asked Jun 05 '18 17:06

Gus


1 Answers

Use below line in AndroidManifest file in Application tag for Android Pi(9) devices

  <uses-library
            android:name="org.apache.http.legacy"
            android:required="false" />
like image 95
Ankush Avatar answered Oct 23 '22 03:10

Ankush