I had a project in eclipse which uses httpcomponents. The jars used in eclipse did not work in Android studio and I am using compileSdkVersion 23 with buildToolsVersion '23.0.2'. I have tried out several solutions and wasted 3 hours figuring out how import the httpcomponents libraries.
To avoid wasting your time, here is how I fixed the issue:
Changes in Module specific build.gradle i.e. /app/build.gradle Add following under android {...}
useLibrary 'org.apache.http.legacy' packagingOptions { exclude 'META-INF/DEPENDENCIES' exclude 'META-INF/NOTICE' exclude 'META-INF/LICENSE' exclude 'META-INF/LICENSE.txt' exclude 'META-INF/NOTICE.txt' }Add following under dependencies {..}
compile ('org.apache.httpcomponents:httpmime:4.3'){ exclude group: 'org.apache.httpcomponents', module: 'httpclient' } compile ('org.apache.httpcomponents:httpcore:4.4.1'){ exclude group: 'org.apache.httpcomponents', module: 'httpclient' } compile 'commons-io:commons-io:1.3.2'
In Top level build.gradle - /build.gradle add the following by replacing earlier statement:
buildscript { ... dependencies { classpath 'com.android.tools.build:gradle:1.3.1' } }
Now gradle sync your project and its done.