I want to use these libraries in Android Studio:
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
I am following a video tutorial in which the tutor is using Eclipse so I know it works.
But what additional things/libraries do I have to add to Android Studio in order to use them?
This question is related to
android
eclipse
android-studio
Main build.gradle - /build.gradle
buildscript {
...
dependencies {
classpath 'com.android.tools.build:gradle:1.3.1'
// Versions: http://jcenter.bintray.com/com/android/tools/build/gradle/
}
...
}
Module specific build.gradle - /app/build.gradle
android {
compileSdkVersion 23
buildToolsVersion "23.0.1"
...
useLibrary 'org.apache.http.legacy'
...
}
HttpClient is deprecated in sdk 23.
You have to move on URLConnection or down sdk to 22
Still you need HttpClient with update gradle sdk 23
You have to add the dependencies of HttpClient in app/gradle as
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:appcompat-v7:23.0.1'
compile 'org.jbundle.util.osgi.wrapped:org.jbundle.util.osgi.wrapped.org.apache.http.client:4.1.2'
...
}
According to the Apache site this is the Gradle dependency you need to include, if you use Android API 23 or newer:
dependencies {
compile group: 'cz.msebera.android' , name: 'httpclient', version: '4.4.1.1'
}
Source: https://hc.apache.org/httpcomponents-client-4.5.x/android-port.html
in case you are going to start development, go fot OkHttp from square, otherwise if you need to keep your previous code running, then add legacy library to your project dependencies:
dependencies {
compile group: 'org.apache.httpcomponents' , name: 'httpclient-android' , version: '4.3.5.1'
}
Use This:-
compile 'org.jbundle.util.osgi.wrapped:org.jbundle.util.osgi.wrapped.org.apache.http.client:4.1.2'
Source: Stackoverflow.com