androidgradleandroid-studioapache-httpcomponentsmultipartentity

Apache HttpClient Android (Gradle)


I have added this line to my build.gradle

compile group: 'org.apache.httpcomponents' , name: 'httpclient-android' , version: '4.3.5'

and I want to use MultipartEntityBuilder in my code. However Android studio doesn't add the library to my code. Can anyone help me with this?


Solution

  • If you are using target SDK as 23 add the below code in your build.gradle

    android{
     useLibrary  'org.apache.http.legacy'
    }
    

    Additional note here: don't try using the gradle versions of those files. They are broken (28.08.15). I tried over 5 hours to get it to work. It just doesn't. not working:

    compile 'org.apache.httpcomponents:httpcore:4.4.1'
    compile 'org.apache.httpcomponents:httpclient:4.5'
    

    Another thing don't use:

    'org.apache.httpcomponents:httpclient-android:4.3.5.1'
    

    It's referring to 21 API level.