2

我希望在我的 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 产生一些冲突吗?

4

2 回答 2

2

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

编辑

到今天为止,还可以使用Apache HttpClient 4.3 的官方端口到 Google Android

于 2012-08-28T11:17:11.057 回答
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 中找到了解决方案

于 2013-05-24T18:24:42.010 回答