The import org.apache.http.client cannot be resolved error when I update sdk to M
Asked Answered
C

4

19

I am getting following errors when I import project into eclipse. I have updated my sdk to M.

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.HttpVersion;
import org.apache.http.NameValuePair;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.params.BasicHttpParams;
import org.apache.http.params.CoreProtocolPNames;
import org.apache.http.params.HttpConnectionParams;
import org.apache.http.params.HttpParams;
import org.apache.http.protocol.HTTP;
Churrigueresque answered 20/9, 2015 at 5:13 Comment(1)
add latest gradle from here mvnrepository.com/artifact/org.apache.httpcomponents/httpclientPalgrave
V
73

For eclipse -- Find library in your sdk and add it manually platforms/android-23/optional/org.apache.http.legacy.jar

For android studio add this line in build.gradle

android {
    useLibrary 'org.apache.http.legacy'
}
Vapid answered 4/2, 2016 at 20:39 Comment(1)
awesome one liner but time saver.Idiomatic
A
9

for android studio add one line in build.gradle file of app like:

android {
       compileSdkVersion 23
       ....
       defaultConfig {
       ..
       ..
       }
 useLibrary 'org.apache.http.legacy'
}
Adriel answered 3/3, 2016 at 6:40 Comment(0)
P
8

apache http and NameValuePair has been deprecated in api 23. youl have to manualy add apache library check this .

or may be you should start using from now HttpURLConnection . check this answer for same

Prolepsis answered 20/9, 2015 at 5:26 Comment(0)
G
0

Another way to achieve the same is,

Find org.apache.http.legacy.jar which is in Android/Sdk/platforms/android-23/optional, add it to your dependency.

Source

Ghent answered 24/8, 2016 at 7:2 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.