Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add Apache HTTP API (legacy) as compile-time dependency to build.grade for Android M?

As mentioned here, Android M will not support the Apache HTTP API. The docs state to:

use the HttpURLConnection class instead.

or

To continue using the Apache HTTP APIs, you must first declare the following compile-time dependency in your build.gradle file:

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

I have converted much of my project's usage of HttpClient to HttpURLConnection, however, I still need to use the HttpClient in a few areas. Hence, I am trying to declare 'org.apache.http.legacy' as a compile-time dependency but am getting an error in build.gradle:

Gradle DSL method not found: 'useLibrary()'

My question is: how do I declare 'org.apache.http.legacy' as a compile-time dependency in my project?

Any help is much appreciated. Thanks

like image 751
Virat Singh Avatar asked Jun 15 '15 23:06

Virat Singh


1 Answers

For API 23:

Top level build.gradle - /build.gradle

buildscript {     ...     dependencies {         classpath 'com.android.tools.build:gradle:1.3.1'     } } ... 

Module specific build.gradle - /app/build.gradle

android {     compileSdkVersion 23     buildToolsVersion "23.0.0"     useLibrary 'org.apache.http.legacy'     ... } 

Official docs (for preview though): http://developer.android.com/about/versions/marshmallow/android-6.0-changes.html#behavior-apache-http-client

Latest android gradle plugin changelog: http://tools.android.com/tech-docs/new-build-system

like image 157
hidro Avatar answered Oct 11 '22 11:10

hidro