After Android 6.0 releases, Support for the Apache HTTP client is removed. If our app is using this client and targets Android 2.3 (API level 9) or higher, HttpURLConnection
class is recommended. It's said that this API is more efficient because it reduces network use through transparent compression and response caching, and minimizes power consumption. If we want to continue using the Apache HTTP APIs, you must first declare the following compile-time dependency in our build.gradl
e file:
android {
useLibrary 'org.apache.http.legacy'
}
The legacy jar is in Android SDK, whose path is sdk/platforms/android-23/optional/
. So, it is nearly independent. Meanwhile, this apache legacy jar is putted into optional/
in Android SDK, so what is optional/
? What does that mean?
Also we know, we can put this jar into libs
and then declare it in our build.gradle
file like this:
dependencies {
compile files('libs/org.apache.http.legacy.jar')
}
Both methods worked as expected when I tested.
But why?
What's the difference between useLibrary
and compile files('')
in build.gradle
? Only because the legacy jar file is in android SDK so I can declare useLibrary
in build.gradle
to use it? Could I use other jars in this way?
Could somebody provide some ideas about this?