22

As we have known that Apache HTTP Client removed in API 23

Apache HTTP Client Removal

However, Volley library currently still uses Apache's library such as

import org.apache.http.Header;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
import org.apache.http.StatusLine;
import org.apache.http.conn.ConnectTimeoutException;
import org.apache.http.impl.cookie.DateUtils;

And I have tested 2 projects: one with compileSdkVersion 22, the other with compileSdkVersion 23, got 2 screenshots:

compileSdkVersion 22

enter image description here

compileSdkVersion 23

enter image description here

I have 2 questions:

  1. Of course, API23 projects using Volley still work successfully. However, I don't understand how they use the Apache's library at runtime, do they find in API22 or lower instead?
  2. Moreover, I wonder if in the near future, will Volley be upgraded so that no longer uses Apache's library? If not, will my current projects still work in the future when Apache's library completely removed and not supported?

Perhaps my English is not so clear, however, hope that you understand my question.

Any explanation will be appreciated.

UPDATE:

From @random's comments, I created a new API23 project using Google's official Volley library (I mean by git clone https://android.googlesource.com/platform/frameworks/volley as Google suggested here), instead of using compile 'com.mcxiaoke.volley:library:1.0.17' in build.gradle file. Yes, got errors with lack of Apache library when building project. Must add useLibrary 'org.apache.http.legacy' into build.gradle file as documented.


2nd UPDATE:

I have just customized Google's volley (as a module in my project) removing Apache library. Please go to my GitHub sample project for your reference. However, please note that it has not been fully tested for all cases, and I have tested only 02 simple cases: GET and POST requests with my web service that is ASP.NET Web API.

BNK
  • 23,994
  • 8
  • 77
  • 87
  • 2
    The more pressing issue IMO is that Volley, which is a Google library, is implemented using deprecated code, which as of v23 is actually excluded from the sources. Using the `useLibrary 'org.apach.http.legacy'` flag is a workaround to keep legacy code when it was intentionally removed. I'd expect Volley to either overhaul the entire code to remove the apache components, or declare that this library will not be developed much further. Things are pretty vague at the moment. – Itai Hanski Nov 26 '15 at 07:31
  • @ItaiHanski: I have just customize Google's volley (as a module in my project) removing Apache library. Please go to my GitHub link https://github.com/ngocchung/VolleyNoApache. Please note that it has not been fully tested for all cases :) – BNK Dec 01 '15 at 07:55
  • 1
    another highly extended option for volley replacement is https://github.com/apptik/jus – kalin Apr 01 '16 at 21:24

6 Answers6

10

It seems there has been quite a mess with the Volley library in Android M. A bug has already been filed for it and acknowledged by google.

https://code.google.com/p/android-developer-preview/issues/detail?id=3013

You should star and track it for any further updates

UPDATE

Regarding your first question, you don't get an error for missing apache files because the library that you're using is still compiled using API 22

ANDROID_BUILD_TARGET_SDK_VERSION=22
ANDROID_BUILD_TOOLS_VERSION=22.0.1
ANDROID_BUILD_SDK_VERSION=22

https://github.com/mcxiaoke/android-volley/blob/master/gradle.properties

Also check this open issue from the library according to which you can add legacy library

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.0"

    useLibrary 'org.apache.http.legacy'
    ...
}
random
  • 10,238
  • 8
  • 57
  • 101
  • Thanks for your answer. Can you provide more information relating to my 1st question? – BNK Sep 09 '15 at 07:04
  • The issue reported says the code will not compile due to missing apache files. Not sure if you've included external apache library and what are your build settings. – random Sep 09 '15 at 07:11
  • I don't include apache in `libs` folder. build.gradle `android { compileSdkVersion 23 buildToolsVersion "23.0.0" defaultConfig { applicationId "..." minSdkVersion 16 targetSdkVersion 23 } buildTypes { release { ... } } } dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) compile 'com.android.support:appcompat-v7:23.0.0' compile 'com.mcxiaoke.volley:library:1.0.17' compile 'com.google.code.gson:gson:2.3' }` – BNK Sep 09 '15 at 07:16
  • `android { compileSdkVersion 23 buildToolsVersion "23.0.0" defaultConfig { applicationId "com.example.simplevolley" minSdkVersion 16 targetSdkVersion 23 versionCode 1 versionName "1.0" } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } } dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) compile 'com.android.support:appcompat-v7:23.0.1' compile 'com.mcxiaoke.volley:library:1.0.17' }` – BNK Sep 09 '15 at 07:19
  • does that mean if I remove API22 from Android SDK, API21 or lower will be used instead (at the present, I have no environment to test) – BNK Sep 09 '15 at 14:07
  • 1
    It might complain you to add API 22 first. It would be good if you add `volley` in the way google suggests to add, library that you're using is not provided by google. It just updates itself from google sources occasionally and has its own build settings. If you add volley in the recommended way you'll have to add external legacy apache library but that ways you'll know how everything is linked together – random Sep 09 '15 at 14:33
  • Thanks! Can you clarify `the way google suggests` more? You mean getting the source code from `GitHub` then compile to `JAR` file, put it into `libs` folder instead of using `compile 'com.mcxiaoke.volley:library:1.0.17'` in build.gradle file? – BNK Sep 09 '15 at 14:40
  • You know, when starting using Volley, I firstly want to use the google source, then I find something missing, as [my question here](http://stackoverflow.com/questions/31737844/android-volley-why-in-jsonarrayrequest-java-has-no-constructor-jsonarrayrequest), please take a look :) – BNK Sep 09 '15 at 14:43
  • 1
    :) volley isn't stable right now, so you'll get such issues. Regarding the `recommended` way, you either include the jar as you mentioned or include it as a module. With the module way, you can go and look into the source code, fix bugs yourself, like adding the missing constructor as mentioned in your other question. You can do that with the jar also but will have to recreate it everytime. If you decide to use volley, you'll have to struggle a bit till it gets more stable. – random Sep 09 '15 at 14:55
  • Your comments are really helpful, thank you very much once again, nice day :) – BNK Sep 09 '15 at 14:58
  • I have just updated my question after testing a new project using Google's official Volley library :) – BNK Sep 10 '15 at 02:01
8

Apache HTTP Client Removal This preview removes support for the Apache HTTP client. If your app is using this client and targets Android 2.3 (API level 9) or higher, use the HttpURLConnection class instead. This API is more efficient because it reduces network use through transparent compression and response caching, and minimizes power consumption. To continue using the Apache HTTP APIs, you must first declare the following compile-time dependency in your build.gradle file:

android {
    useLibrary 'org.apache.http.legacy'
}

Android is moving away from OpenSSL to the BoringSSL library. If you’re using the Android NDK in your app, don't link against cryptographic libraries that are not a part of the NDK API, such as libcrypto.so and libssl.so. These libraries are not public APIs, and may change or break without notice across releases and devices. In addition, you may expose yourself to security vulnerabilities. Instead, modify your native code to call the Java cryptography APIs via JNI or to statically link against a cryptography library of your choice.

Nooruddin Lakhani
  • 7,507
  • 2
  • 19
  • 39
  • Thanks! However, my projects don't use Apache's library directly, just use Volley, so no need to declare that line in build.gradle – BNK Sep 09 '15 at 08:06
  • Hi! Your answer will works fine for API23 projects using official volley from Google (I mean by `git clone https://android.googlesource.com/platform/frameworks/volley`). Thanks – BNK Sep 10 '15 at 01:48
2
android {
    useLibrary 'org.apache.http.legacy'
}

dependencies {
    compile 'commons-httpclient:commons-httpclient:3.1'
}
itzhar
  • 12,743
  • 6
  • 56
  • 63
1

Add this to the de dependencies of your app, and then works correctly:

dependencies { ... compile 'org.jbundle.util.osgi.wrapped:org.jbundle.util.osgi.wrapped.org.apache.http.client:4.1.2' }

  • Hi! As I mentioned in my question, API23 projects using Volley still work successfully – BNK Sep 09 '15 at 14:10
0

It's one huge hysteria about Apache's HTTP client. You can continue using it in any project you want without any consequences. Why waste time porting code to other libraries? I described the best way to continue using Apache's libraries here: https://stackoverflow.com/a/37623038/1727132 (spoiler: don't use legacy version!)

Community
  • 1
  • 1
Jehy
  • 4,729
  • 1
  • 38
  • 55
0

Appache Http is removed from android API level 23 if you still using the Apache Http client you can include android { useLibrary 'org.apache.http.legacy'} in your project - module build.gradle

Abhijit Chakra
  • 3,201
  • 37
  • 66