Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android - Apache Mime & httpClient

I am trying to send a file to a server using HttpEntity

HttpEntity mpEntity = MultipartEntityBuilder.create().addBinaryBody("file", file, ContentType.create("image/jpeg"), file.getName()).build();

However in order to use this I need to import the mime libraries to my project. When in my gradle.build I add:

    compile 'org.apache.httpcomponents:httpmime:4.3.4'

I am getting the following errors warnings which result in the libraries not imported:

WARNING: Dependency org.apache.httpcomponents:httpclient:4.3.4 is ignored for debug as it may be conflicting with the internal version provided by Android.
     In case of problem, please repackage it with jarjar to change the class packages

Any ideas what I need to do so I can successfully import those libraries?

like image 224
frek13 Avatar asked Jul 28 '14 14:07

frek13


1 Answers

Building with gradle from command line will do the trick.

 ./gradlew installDebug

You will see then that the prompt Android Studio gave is a warning only:

WARNING: Dependency org.apache.httpcomponents:httpclient:4.3.4 is ignored for Snapshot as it may be conflicting with the internal version provided by Android. In case of problem, please repackage it with jarjar to change the class packages

--- Here is some extra in case you meet another issue connected to apache-http ---

In my case i had to add some packaging options too due to a bug with the android-gradle-plugin:

android {
    packagingOptions {
        exclude 'META-INF/DEPENDENCIES'
        exclude 'META-INF/NOTICE'
        exclude 'META-INF/NOTICE.txt'
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/LICENSE.txt'
    }
}

For more info regarding this look into this ticket -> https://stackoverflow.com/questions/20673625/android-gradle-plugin-0-7-0-duplicate-files-during-packaging-of-apk.

like image 124
Ostkontentitan Avatar answered Oct 31 '22 16:10

Ostkontentitan