8

I try to include httpmime in my application using the build.gradle file, and everything compiles fine. Instead, when the application tries to actually use the MultipartEntityBuilder class, there are a bunch of WARN level messages on the log saying that there are problems.

Here's the excerpt from my build.gradle for the dependency:

 compile('org.apache.httpcomponents:httpmime:4.+') { exclude module: "httpclient" } 

Here are the errors:

 10-09 13:39:37.367 2409-2426/com.company.app W/dalvikvm﹕ VFY: unable to resolve static field 6967 (DEFAULT_BINARY) in Lorg/apache/http/entity/ContentType; 10-09 13:39:37.367 2409-2426/com.company.app W/dalvikvm﹕ VFY: unable to find class referenced in signature (Lorg/apache/http/entity/ContentType;) 10-09 13:39:37.367 2409-2426/com.company.app W/dalvikvm﹕ VFY: unable to find class referenced in signature (Lorg/apache/http/entity/ContentType;) 10-09 13:39:37.367 2409-2426/com.company.app W/dalvikvm﹕ VFY: unable to resolve static field 6967 (DEFAULT_BINARY) in Lorg/apache/http/entity/ContentType; 10-09 13:39:37.367 2409-2426/com.company.app W/dalvikvm﹕ VFY: unable to find class referenced in signature (Lorg/apache/http/entity/ContentType;) 10-09 13:39:37.367 2409-2426/com.company.app W/dalvikvm﹕ VFY: unable to find class referenced in signature (Lorg/apache/http/entity/ContentType;) 10-09 13:39:37.367 2409-2426/com.company.app W/dalvikvm﹕ VFY: unable to resolve static field 6967 (DEFAULT_BINARY) in Lorg/apache/http/entity/ContentType; 10-09 13:39:37.367 2409-2426/com.company.app W/dalvikvm﹕ VFY: unable to find class referenced in signature (Lorg/apache/http/entity/ContentType;) 10-09 13:39:37.367 2409-2426/com.company.app W/dalvikvm﹕ VFY: unable to find class referenced in signature (Lorg/apache/http/entity/ContentType;) 10-09 13:39:37.377 2409-2426/com.company.app W/dalvikvm﹕ VFY: unable to resolve static method 19478: Lorg/apache/http/util/Args;.notNull (Ljava/lang/Object;Ljava/lang/String;)Ljava/lang/Object; 10-09 13:39:37.377 2409-2426/com.company.app W/dalvikvm﹕ VFY: unable to resolve static field 6968 (DEFAULT_TEXT) in Lorg/apache/http/entity/ContentType; 10-09 13:39:37.377 2409-2426/com.company.app W/dalvikvm﹕ VFY: unable to find class referenced in signature (Lorg/apache/http/entity/ContentType;) 10-09 13:39:37.377 2409-2426/com.company.app W/dalvikvm﹕ VFY: unable to find class referenced in signature (Lorg/apache/http/entity/ContentType;) 

The java class:

 import android.util.Log; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.net.HttpURLConnection; import java.net.URL; import org.apache.http.HttpEntity; import org.apache.http.entity.mime.MultipartEntityBuilder; public class FileUploader { private final static String BOUNDARY = "__--__--__SERVETHEOVERMIND-__-_"; public void uploadFile(String targetUrl, MultipartEntityBuilder upload, UploadHandler after) { Log.v("FileUploader", "Uploading to " + targetUrl); HttpURLConnection con = null; OutputStream os = null; InputStream is = null; try { HttpEntity uploadEntity = upload.build(); URL postTo = new URL(targetUrl); con = (HttpURLConnection) postTo.openConnection(); con.setRequestMethod("POST"); con.setRequestProperty("Content-Type", "multipart/form-data;boundary=" + BOUNDARY); con.setDoOutput(true); con.setDoInput(true); con.setUseCaches(false); con.addRequestProperty("Connection", "Keep-Alive"); con.setRequestProperty("Content-length", String.valueOf(uploadEntity.getContentLength())); os = con.getOutputStream(); uploadEntity.writeTo(os); os.close(); con.connect(); is = con.getInputStream(); after.consumeUploadResponse(is); con.disconnect(); } catch (IOException e) { e.printStackTrace(); } if(con != null) { con.disconnect(); } if(os != null) { try { os.close(); } catch (IOException e) { Log.v("Uploader", "Closed output stream"); } } if(is != null) { try { is.close(); } catch (IOException e) { Log.v("Uploader", "Closed input stream"); } } } public interface UploadHandler { public void consumeUploadResponse(InputStream stream); } } 

[EDIT] Correct Dependencies, as per answer

 compile('org.apache.httpcomponents:httpmime:4.+') { exclude module: "httpclient" } compile('org.apache.httpcomponents:httpcore:4.+') { exclude module: "httpclient" } 

[SECOND EDIT] Still having issues - now it's these other missing bits, but it might be problems on the backend:

 10-10 11:51:54.998 29597-29638/com.company.app W/dalvikvm﹕ VFY: unable to resolve static field 7465 (INSTANCE) in Lorg/apache/http/message/BasicHeaderValueParser; 10-10 11:51:54.998 29597-29638/com.company.app W/dalvikvm﹕ VFY: unable to resolve static field 7459 (INSTANCE) in Lorg/apache/http/message/BasicHeaderValueFormatter; 

[YET ANOTHER EDIT]

It seems the last little missing bits don't have any effect on the successful use of the MultipartEntityBuilder in this case.

2
  • Did you manage to remove the Lorg/apache/http/message.... static field warnings? I seem to e having a similar issue now. Commented Oct 29, 2014 at 22:04
  • your first code block above fixed the warning i was getting in android studio. Thanks! Commented Dec 2, 2014 at 16:18

3 Answers 3

13

This is how I did in my gradle..

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' } } 

And inside android

android{ packagingOptions { exclude 'META-INF/DEPENDENCIES' exclude 'META-INF/NOTICE' exclude 'META-INF/LICENSE' } } 
Sign up to request clarification or add additional context in comments.

Comments

8

You need to add httpcore-4.3.jar to your java build path. I had the same problem and it's gone after adding this jar.

3 Comments

I thought that was it, but I'm still stuck on similar issues
It looks like it probably works, despite the latest error messages - now I'm looking at issues on the rails backend
If you are new to Android Studio and now sure how to add the jar to your build path, see this answer to a similar question: stackoverflow.com/a/28712564 - you just need to search from httpcore instead of httpmime.
0
 compile group: 'org.apache.httpcomponents' , name: 'httpclient-android' , version: '4.3.5.1' compile('org.apache.httpcomponents:httpmime:4.3') { exclude module: "httpclient" } 

You can use this above dependencies to the build.gradle (Module:app) to your Project for the following IMPORT statements

import org.apache.http.entity.ContentType; import org.apache.http.entity.mime.MIME;

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.