HttpClient won't import in Android Studio
HttpClient
is not supported any more in sdk 23. You have to use URLConnection
or downgrade to sdk 22 (compile 'com.android.support:appcompat-v7:22.2.0'
)
If you need sdk 23, add this to your gradle:
android {
useLibrary 'org.apache.http.legacy'
}
You also may try to download and include HttpClient jar directly into your project or use OkHttp instead
Can't import org.apache.http.HttpResponse in Android Studio
HttpClient was deprecated in Android 5.1 and is removed from the Android SDK in Android 6.0. While there is a workaround to continue using HttpClient in Android 6.0 with Android Studio, you really need to move to something else. That "something else" could be:
- the built-in classic Java
HttpUrlConnection
- Apache's independent packaging of HttpClient for Android
- OkHttp (my recommendation)
- AndroidAsync
Or, depending upon the nature of your HTTP work, you might choose a library that supports higher-order operations (e.g., Retrofit for Web service APIs).
In a pinch, you could enable the legacy APIs, by having useLibrary 'org.apache.http.legacy'
in your android
closure in your module's build.gradle
file. However, Google has been advising people for years to stop using Android's built-in HttpClient, and so at most, this should be a stop-gap move, while you work on a more permanent shift to another API.
HttpClient is not imprting in Android studio
Download jar file HttpClient.jar.Then add into lib folder on your project.Then fix the path on settings
File -> Project Structure -> Dependencies -> Add -> File Dependency
Android Studio opens a dialog box where you can drag&drop the jar library. Then click the OK button.
httpclient conflict with classes now provided by Android
Check out this changelog for the Android API.
You should replace the Apache HTTP functions by HttpURLConnection or use this snipped in your build.gradle
to continue using the now deprecated Apache libraries.
android {
useLibrary 'org.apache.http.legacy'
}
Android Gradle Apache HttpClient does not exist?
I suggest you replace the deprecated apache HttpClient with the new HttpURLConnection.
That's a cleaner solution, it's quite easy to migrate, and generally it's better to stick to the latest SDK changes than trying to hack/patch/workaround: you usually regret it later :)
Step 1
HttpGet httpGet = new HttpGet(url);
becomes:
URL urlObj = new URL(url);
Step 2
HttpClient httpClient = new DefaultHttpClient();
HttpContext localContext = new BasicHttpContext();
HttpResponse response = httpClient.execute(httpGet, localContext);
InputStream is = response.getEntity().getContent();
becomes:
HttpURLConnection urlConnection = (HttpURLConnection) urlObj.openConnection();
InputStream is = urlConnection.getInputStream();
Step 2 bis
int status = response.getStatusLine().getStatusCode();
becomes:
int status = urlConnection.getResponseCode();
Related Topics
How to Save/Store Objects in Sharedpreferences on Android
Determine If Android App Is Being Used For the First Time
How to Find Out Which Keystore Was Used to Sign an App
How to Get Apk Signing Signature
Android Camera: Data Intent Returns Null
Location of SQLite Database on the Device
Put Constant Text Inside Edittext Which Should Be Non-Editable - Android
Custom Toast on Android: a Simple Example
How to Delete an Sms from the Inbox in Android Programmatically
How to Parse the Androidmanifest.Xml File Inside an .Apk Package
Checkbox in Recyclerview Keeps on Checking Different Items
How to Refresh App Upon Shaking the Device
How to Make Wrap_Content Work on a Recyclerview
Open Application After Clicking on Notification
Listen to Volume Buttons in Background Service