简体   繁体   中英

How to add compile time dependency in eclipse

In the developer.android.com site I saw the below information under the Android 6.0 changes.

Apache HTTP Client Removal


Android 6.0 release removes support for the Apache HTTP client. If your app is using this client and targets Android 2.3 (API level 9) or higher, use the HttpURLConnection class instead. This API is more efficient because it reduces network use through transparent compression and response caching, and minimizes power consumption. 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 }

Problem:

I am using eclipse and have used the HTTP client. To use the new HttpURLConnection how can I add the dependency in Eclipse IDE? Or I have to use the Android Studio to use this new feature?

Thanks for looking and giving solution to this problem.

You need to add org.apache.http.legacy to your libs folder.

This jar will be found from

Your SDK path \\android-sdk\\platforms\\android-23\\optional

Copy file from here and add it to your libs folder.

Also it would be better if you use Android Studio .

Thanks..!!

@SENTHILKUMAR S You should use Android Studio .

useLibrary adds the library to classpath while compiling but does not bundle the library with the application. Courtesy @laalto Sir .

Please upgrade the Gradle tools version in your build.gradle file of Android Studio , as follows:

dependencies {
    classpath 'com.android.tools.build:gradle:1.3.0' //2.3.0
}

For more info you can check

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

For those stuck using Eclipse (ie. open-source project you do not own), here is a solution for using org.apache.http.legacy, as per the original question .

Insert this inside the application tag on the manifest file, on all project instances that uses the legacy apache classes:

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

Courtesy of https://stackoverflow.com/a/33512294/461982

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM