I have a simple class written in Android Studio:
package com.mysite.myapp;
import org.apache.http.client.HttpClient;
public class Whatever {
public voi
For android API 28 and higher in Manifest.xml inside application tag
<application
.
.
.
<uses-library android:name="org.apache.http.legacy" android:required="false"/>
HttpClient is not supported in sdk 23 and 23+.
If you need to use into sdk 23, add below code to your gradle:
android {
useLibrary 'org.apache.http.legacy'
}
Its working for me. Hope useful for you.
I think depending on which Android Studio version you have, it's important you update your android studio as well, i was becoming frustrated too following everyone's advice but no luck, until i had to upgrade my android version from 1.3 to 1.5, the errors disappeared like magic.
If you want import some class like :
import org.apache.http.NameValuePair;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.params.BasicHttpParams;
import org.apache.http.params.HttpConnectionParams;
import org.apache.http.params.HttpParams;
You can add the following line in the build.gradle (Gradle dependencies)
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:27.1.0'
implementation 'com.android.support:support-v4:27.1.0'
.
.
.
implementation 'org.jbundle.util.osgi.wrapped:org.jbundle.util.osgi.wrapped.org.apache.http.client:4.1.2'
}
Another way is if you have httpclient.jar file then you can do this :
Paste your .jar file in "libs folder" in your project. Then in gradle add this line in your build.gradle(Module:app)
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:appcompat-v7:23.0.0'
compile files('libs/httpcore-4.3.3.jar')
}
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