2

I wish to include the latest version of Http with my Android App, which is 4.2.1. Now wish to download the library from Apache website and include it in the libs folder and then to the build path of my app.

On including Http - 4.2.1, I got the following output in the 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

My question is can I do this? Will this create some conflict with already included version of Http library along with the SDK?

Gaurav Agarwal
  • 18,754
  • 29
  • 105
  • 166
  • If you are importing that library and create objects using it explicitly (and are not importing a conflicting library in the same namespace) everything should work well. Why would it not? – Kickaha Aug 27 '12 at 18:35
  • Ok, thanks, I think this answers the question. – Gaurav Agarwal Aug 27 '12 at 18:40
  • Ill make an answer out of it then! – Kickaha Aug 27 '12 at 18:44
  • If you are importing that library and create objects using it explicitly (and are not importing a conflicting library in the same namespace) everything should work well. – Kickaha Aug 27 '12 at 18:44
  • Android SDK has Http build into it, how would I know the class I am importing is from added jar or from SDK. – Gaurav Agarwal Aug 27 '12 at 20:35

2 Answers2

2

Unfortunately this problem does not have an elegant and clean solution. The only option you have is to move all HttpClient classes to a custom namespace ('org.apache.http' -> 'my.http') using maven shade plugin or using a prepackaged fork of the library available here

EDIT

As of today one can also use the official port of Apache HttpClient 4.3 to Google Android.

ok2c
  • 26,450
  • 5
  • 63
  • 71
  • Thanks Oleg, How unfortunate? – Gaurav Agarwal Aug 28 '12 at 13:51
  • 1
    @coding crow: Just imagine how I feel being that very stupid idiot who advocated the idea of rushing the freeze of unfinished 4.0 APIs in order to help Google with the first release of Android. – ok2c Aug 28 '12 at 14:13
  • 1
    If I am assuming correct you are Oleg Kalnichevski. We all appreciate and are thankful of work at http-4.2.1. My belief is Android should figure out some way of introducing new libraries. You work is amazing, keep it going, we will figure out a way. – Gaurav Agarwal Aug 28 '12 at 14:19
  • @coding crow: lots of people enjoy bitching about HttpClient APIs these days not actually knowing how much of it is the direct result of rushing the API freeze in order to be in time for Android 1.0. I have been gradually rewriting and deprecating a lot of old code. Once 4.3 is released it should be possible to deploy HC 4.3 with minimal changes in parallel to HC 4.0beta1 shipped with Android without running into classloader conflicts. – ok2c Aug 28 '12 at 14:39
  • That is great. HttpClient is a very important API and web is full of community support for it. Let people bitch, I am using it and lot of great apps out there are using it. I know Instagram is using it. Here is very good library for Android HttpClient http://loopj.com/android-async-http/. So great work. – Gaurav Agarwal Aug 28 '12 at 16:13
0
<classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK">
<accessrules>
<accessrule kind="nonaccessible" pattern="org/apache/http/**"/>
</accessrules>
</classpathentry>

i fix it modify application's .classpath file like this and i was find the solution in open source project open-gpstracker

huntersea
  • 29
  • 3