Volley 1.1 dependency on org.apache.http
Asked Answered
L

1

11

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.

Lentigo answered 5/6, 2018 at 17:10 Comment(2)
What are you using for unit testing? Mockito? RoboElectric? Junit4 or 5? It's possible the test framework is for some reason defaulting down to a lower minSDK verision, thus forcing the need for Apache HTTP. If that is the case, put a manifest in your testing folder that sets the minsdk higher.Diagonal
Note; You can't use volley from a non-instrumented unit test on Android - see github.com/google/volley/issues/346Olivette
P
4

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" />
Pyrazole answered 16/11, 2018 at 12:14 Comment(1)
You should explain why this is the solution :)Normie

© 2022 - 2024 — McMap. All rights reserved.