0

I want to build a project, that uses Apache HTTP client, for Android P. As far as I understand, there are 2 ways to do this:

First via AndroidManifest.xml:

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

Second via build.gradle:

android {
    useLibrary 'org.apache.http.legacy'
}

Are these ways equivalent?

Why android.useLibrary command in build gradle DOES NOT add the uses-library tag in AndroidManifest.xml?

Tanveer Munir
  • 1,956
  • 1
  • 12
  • 27
prog mob
  • 41
  • 1
  • 7
  • 2
    "I want to build a project, that uses Apache http client" -- use [the independent library](http://hc.apache.org/httpcomponents-client-4.3.x/android-port.html). – CommonsWare Apr 08 '19 at 11:26

2 Answers2

1

Extending what CommonsWare commented.

Use gradle dependency to use apache http client, don't modify AndroidManifest.xml.

Modify your build.gradle as

dependencies {
    implementation 'org.apache.httpcomponents:httpclient-android:4.3.5.1'
}
Rodrigo Graça
  • 1,985
  • 3
  • 17
  • 24
Ranjan Kumar
  • 1,164
  • 7
  • 12
-1

Adding this to AndroidManifest.xml should notify Android at runtime these classes exist:

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

Reference: specify_requirement_for_apache_http_legacy_library

The build.gradle declaration makes sure the library is available at compile time.

useLibrary 'org.apache.http.legacy'

Reference: behavior-apache-http-client

farhanjk
  • 1,652
  • 16
  • 17