我尝试使用build.gradle文件在我的应用程序中包含httpmime,所有的东西都编译得很好。相反,当应用程序尝试实际使用MultipartEntityBuilder类时,日志上有一堆警告级消息表示存在问题。
以下是我的build.gradle中关于依赖关系的节选:
compile('org.apache.httpcomponents:httpmime:4.+') { exclude module: "httpclient" }
以下是错误:
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;)
Java班:
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); } }
[编辑]根据答案更正依赖项
compile('org.apache.httpcomponents:httpmime:4.+') { exclude module: "httpclient" } compile('org.apache.httpcomponents:httpcore:4.+') { exclude module: "httpclient" }
[第二次编辑]仍然有问题-现在是这些其他缺失的位,但可能是后端的问题:
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;
[又一次编辑]
在本例中,最后缺少的部分似乎对MultipartEntityBuilder的成功使用没有任何影响。
您需要将httpcore-4.3.jar添加到您的Java构建路径中。我也有同样的问题,加了这个罐子后就没了。
反应器中的项目包含循环引用:Vertex{tag='org.spigotmc: spiget-api: 1.8.8-R0.1-SNAPSHOT'}'和'Vertex{tag='org.spigotmc: spigot: 1.8.8-R0.1-SNAPSHOT'}'之间的边缘在图中引入循环org.spigotmc: spigot: 1.8.8-R0.1-SNAPSHOT- “Vertex { lab
在我的Android Studio项目中,我有两个子项目/模块:一个Android应用程序()和一个Android库项目()。依赖于。到目前为止还不错。 但是,需要导入AAR库才能正常工作。 因此我的配置如下: 包含 包含 现在,要包含我使用下面详细介绍的方法: 如何使用新的Gradle Android Build系统手动包含外部aar包 因此,在我的的中,我基本上有: 显然,我将dependen
我在eclipse中有一个java项目,我在ec利pse之外使用ivy依赖项管理器,所以我的目录结构中充满了各种jar文件。有没有一种简单的方法将我的eclipse项目的路径指向常春藤目录并拾取所有jar文件? 我试图避免将每个单独的jar拉到我的eclipse项目目录中,并希望有更好的方法。
创建一个新的android项目后,Eclipse会自动创建一个“appcompat_v7”项目,在/src下没有任何文件。但它显示了样式错误。下一行是styles.xml中的第18行。 样式名称=“Widget.MediaRouter.MediaRouteButton” 父=“Widget.AppCompat.ActionButton” 我不知道Eclipse如何或为什么创建这个项目。 我是And
我正在使用sbt 0.13.12,这是我的项目 在构建中。sbt取决于公共。如果我按sbt project sub1 run运行就可以了。但是,当我将子项目打包为jar文件时,我运行sub1。jar文件中,错误显示sub1无法找到一类公共的。 我的目的是包装sub1。jar和sub2。在每个jar文件中编译带有通用代码的jar。 --更新-- 我尝试作为建议回答。运行时遇到这个问题: 而且,是的!