包含Http-4.2.1和Android App

时间:2012-08-27 17:54:06

标签: android apache http version apache-httpclient-4.x

我希望在我的Android应用程序中包含最新版本的Http,即4.2.1。现在希望从Apache网站下载该库,并将其包含在libs文件夹中,然后包含到我的应用程序的构建路径中。

在包含Http-4.2.1时,我在logcat中得到了以下输出

08-28 02:42:40.917: D/dalvikvm(25641): DexOpt: 'Lorg/apache/http/client/ResponseHandler;' has an earlier definition; blocking out
08-28 02:42:40.917: D/dalvikvm(25641): DexOpt: 'Lorg/apache/commons/codec/Decoder;' has an earlier definition; blocking out
08-28 02:42:40.927: D/dalvikvm(25641): DexOpt: 'Lorg/apache/commons/codec/BinaryDecoder;' has an earlier definition; blocking out
08-28 02:42:40.927: D/dalvikvm(25641): DexOpt: 'Lorg/apache/commons/codec/Encoder;' has an earlier definition; blocking out
08-28 02:42:40.927: D/dalvikvm(25641): DexOpt: 'Lorg/apache/commons/codec/BinaryEncoder;' has an earlier definition; blocking out
08-28 02:42:40.927: D/dalvikvm(25641): DexOpt: 'Lorg/apache/commons/codec/DecoderException;' has an earlier definition; blocking out
08-28 02:42:40.927: D/dalvikvm(25641): DexOpt: 'Lorg/apache/commons/codec/EncoderException;' has an earlier definition; blocking out
08-28 02:42:40.927: D/dalvikvm(25641): DexOpt: 'Lorg/apache/commons/codec/StringDecoder;' has an earlier definition; blocking out
08-28 02:42:40.927: D/dalvikvm(25641): DexOpt: 'Lorg/apache/commons/codec/StringEncoder;' has an earlier definition; blocking out
08-28 02:42:40.927: D/dalvikvm(25641): DexOpt: 'Lorg/apache/commons/codec/StringEncoderComparator;' has an earlier definition; blocking out
08-28 02:42:40.937: D/dalvikvm(25641): DexOpt: 'Lorg/apache/commons/codec/binary/Base64;' has an earlier definition; blocking out
08-28 02:42:42.847: D/dalvikvm(25641): DexOpt: not verifying 'Lorg/apache/http/HeaderElement;': multiple definitions
08-28 02:42:42.847: D/dalvikvm(25641): DexOpt: not verifying 'Lorg/apache/http/HeaderElementIterator;': multiple definitions
08-28 02:42:42.847: D/dalvikvm(25641): DexOpt: not verifying 'Lorg/apache/http/HeaderIterator;': multiple definitions
08-28 02:42:42.847: D/dalvikvm(25641): DexOpt: not verifying 'Lorg/apache/http/HttpConnection;': multiple definitions
08-28 02:42:42.847: D/dalvikvm(25641): DexOpt: not verifying 'Lorg/apache/http/HttpClientConnection;': multiple definitions
08-28 02:42:42.847: D/dalvikvm(25641): DexOpt: not verifying 'Lorg/apache/http/HttpConnectionMetrics;': multiple definitions
08-28 02:42:42.847: D/dalvikvm(25641): DexOpt: not verifying 'Lorg/apache/http/HttpEntity;': multiple definitions
08-28 02:42:42.857: D/dalvikvm(25641): DexOpt: not verifying 'Lorg/apache/http/HttpMessage;': multiple definitions
08-28 02:42:42.857: D/dalvikvm(25641): DexOpt: not verifying 'Lorg/apache/http/HttpRequest;': multiple definitions
08-28 02:42:42.857: D/dalvikvm(25641): DexOpt: not verifying 'Lorg/apache/http/HttpEntityEnclosingRequest;': multiple definitions
08-28 02:42:42.857: D/dalvikvm(25641): DexOpt: not verifying 'Lorg/apache/http/HttpException;': multiple definitions
08-28 02:42:42.857: D/dalvikvm(25641): DexOpt: not verifying 'Lorg/apache/http/HttpHost;': multiple definitions
08-28 02:42:42.857: D/dalvikvm(25641): DexOpt: not verifying 'Lorg/apache/http/HttpInetConnection;': multiple definitions
08-28 02:42:42.857: D/dalvikvm(25641): DexOpt: not verifying 'Lorg/apache/http/HttpRequestFactory;': multiple definitions

我的问题我可以这样做吗?这是否会与已包含的Http库版本以及SDK一起产生冲突?

2 个答案:

答案 0 :(得分:2)

不幸的是,这个问题没有优雅和干净的解决方案。您唯一的选择是使用maven shade插件或使用可用库的预先打包的分支将所有HttpClient类移动到自定义命名空间('org.apache.http' - >'my.http')here

修改

截至今天,我们也可以使用官方port of Apache HttpClient 4.3 to Google Android

答案 1 :(得分:0)

<classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK">
<accessrules>
<accessrule kind="nonaccessible" pattern="org/apache/http/**"/>
</accessrules>
</classpathentry>

我修复它修改应用程序的.classpath文件 我在开源项目open-gpstracker中找到了解决方案