Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New Android 5.1 Deprecated classes which could affect on the library in future #830

Closed
SlavVv opened this issue Mar 18, 2015 · 49 comments
Closed
Assignees
Labels
Milestone

Comments

@SlavVv
Copy link

SlavVv commented Mar 18, 2015

The org.apache.http classes and the AndroidHttpClient class have been deprecated in Android 5.1.

This is from the new Android 5.1 APIs update. https://developer.android.com/about/versions/android-5.1.html#http

@panxw
Copy link

panxw commented Mar 20, 2015

Maybe you could transfer to android volley, or implement this library by URLConnection.
http://developer.android.com/reference/java/net/URLConnection.html

@dkozel
Copy link

dkozel commented Mar 30, 2015

smarek has said that the library will use a port of the Apache HttpClient for future releases as the version shipped with Android is frozen (and now deprecated) at 4.0 beta.
https://hc.apache.org/httpcomponents-client-4.3.x/android-port.html

"in branch 1.5.0 we plan on go away from Android provided version of HttpClient and replace it with android port" -smarek #775

@smarek smarek self-assigned this Apr 2, 2015
@smarek smarek added this to the 1.5.0 milestone Apr 2, 2015
@smarek smarek added the moderate label Apr 2, 2015
@smarek
Copy link
Member

smarek commented Apr 2, 2015

Thank you and yes, I'll be pushing 1.5.0 branch forward, so we won't fall into problems as those classes will be removed in future Android version.

@kjkrum
Copy link

kjkrum commented Jun 24, 2015

Apache HTTP has been removed from the M preview: http://developer.android.com/preview/behavior-changes.html

@titanseason
Copy link

@kjkrum Android-async-http works well on Android M, I debuged this last week

@smarek
Copy link
Member

smarek commented Jul 13, 2015

@titanseason should not work, how come?

@kjkrum
Copy link

kjkrum commented Jul 13, 2015

@titanseason What version? Only the 1.5.x branch should work on M. If an earlier version works, Google might have "removed" Apache HTTP by removing it from the Android SDK stub library, similar to the way they remove methods with the @hide annotation. This would make sense, since it would prevent massive breakage of existing apps. If this is how they handled it, future versions of android-async-http could be built against a stub library of Apache HTTP instead of incorporating the whole thing and bloating apps that use it.

@kjkrum
Copy link

kjkrum commented Jul 13, 2015

(Though that would be a gamble, since Google might actually remove Apache HTTP at some point in the future.)

@titanseason
Copy link

@kimiyash
I download Android M preview image for Nexus 5 at https://developer.android.com/preview/download.html, and update my Nexus 5 Device with the image.

Android-async-http (Version 1.4.6) works well on my Nexus 5.

By the way, my Android project target in project.properties is "target=android-19"

@kjkrum
Copy link

kjkrum commented Jul 13, 2015

Then they must have only removed Apache HTTP from the stub library. Version 1.4.x will continue to run, it just won't be compilable against M or later SDKs.

@bytebeats
Copy link

Will HttpClient be replaced by HttpUrlConnection or other alternative in android-async-http? I think this is a final solution.

@smarek
Copy link
Member

smarek commented Aug 18, 2015

Nope, we discussed this already, and there are already good libraries based on HttpUrlConnection, we're not going to implement that again. Version 1.5.0 (as soon as I get some time to push it forward) will be based on Apache HttpComponents 4.3+ (see #830 (comment) and #775)

@gmbett
Copy link

gmbett commented Aug 18, 2015

If you change your target sdk to Android M (API 23) then all deprecated classes related to HTTP client are no longer available and Android-async-http won't work.

You need to add "useLibrary 'org.apache.http.legacy'" in your gradle configuration.

@panxw
Copy link

panxw commented Aug 18, 2015

@smarek
Copy link
Member

smarek commented Aug 18, 2015

@gmbett good tip!
@panxw up to 5.1 (API22) everything works, it's API 23 Android Marshmallow (currently in preview) that' causing the troubles.

@hanbo
Copy link

hanbo commented Aug 20, 2015

There is a org.apache.http.legacy.jar in Android/sdk/platforms/android-23/optional which can be used as a workaround for eclipse based projects.

@zhangchaoxu
Copy link
Contributor

give a tip for someone just like me, do not know how to add "useLibrary 'org.apache.http.legacy'"
just follow this

  1. upgrade the build gradle to lastest version in /build.gradle
    buildscript { ... dependencies { classpath 'com.android.tools.build:gradle:1.3.1' } }
  2. and then add org.apache.http.legacy in module like app/build.gradle
    android { compileSdkVersion 23 buildToolsVersion "23.0.0" useLibrary 'org.apache.http.legacy' ... }

@zhangchaoxu
Copy link
Contributor

wow, i am sorry to said that, there is still a compile issue said that org.apache.http related class can not found, even after i added useLibrary 'org.apache.http.legacy' in my project's gradle configuration.
finally, i copied org.apache.http.legacy.jar from sdk/platforms/android-23/optional to libs folder of my module, and it works.

@gmbett , does useLibrary 'org.apache.http.legacy' works in your case, any other tips? Thanks

@TylerMcCraw
Copy link

@zhangchaoxu thanks for the tips on the workaround.

Hopefully, @smarek will be able to resolve this for 1.5.0. Granted, I'm sure it will take quite a bit of work to refactor it so that there are no dependencies on org.apache.http.Header.
Thanks for helping out with this, @smarek!

@TylerMcCraw
Copy link

@zhangchaoxu, did you have to do anything to your project after copying org.apache.http.legacy.jar to your libs folder? My project still shows compilation issues after doing this.

@kjkrum
Copy link

kjkrum commented Aug 23, 2015

i copied org.apache.http.legacy.jar from sdk/platforms/android-23/optional to libs folder of my module, and it works.

Have you tested it on a device, or just compiled it? My understanding is that org.apache.http.legacy is just a stub library, and if you compile it into your app it'll crash at runtime.

@zhangchaoxu
Copy link
Contributor

@TylerMcCraw
just add compile fileTree(dir: 'libs', include: ['*.jar']) or compile files('libs/org.apache.http.legacy.jar') into the dependencies of the module's build.gradle, and then sync it.

@kjkrum
yes, i have tested in genymotion vm with 4.4 and 5.0/an old HTC mobile with Android 4.0/Nexus5 with Android5.0, all of above works well.
Maybe i need to test in Android 6.0 as well, thanks for your advise.

@zhangchaoxu
Copy link
Contributor

@kjkrum
already tested in Android6.0 with AVD, and it works well.

@griffins
Copy link

griffins commented Sep 2, 2015

I thought someone assigned himself this issue. Else we should try to port
this library to use HttpUrlConnection. I don't know a lot about http but am
willing to do some research and help.

On Wed, 2 Sep 2015 06:58 Dennis Jung notifications@github.com wrote:

In android document, it comments to define library on build.gradle to use
apache library.

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

Android suggest to use HttpURLConnection for alternative, and I wonder is
there a plan or way to switch into on it.


Reply to this email directly or view it on GitHub
#830 (comment)
.

@smarek
Copy link
Member

smarek commented Sep 2, 2015

@griffins I'm assigned but I don't have the time to fix all this right now.
If you're willing to contribute and do some research, would be great to provide script to repackage production version of HttpClient-4.X, which is main issue we're solving right now.

There are good HttpUrlConnections based async http requesting libraries out there, but this one was and will be based on HttpClient, no need to do just another library like those.

We need to have JAR of Apache HttpClient components (all of them) but not under org.apache, as that would cause classpath conflicts, but under different namespace (such as com.loopj.httpclient)

Something like that was done previously, see HttpClientAndroidLib project (now unmaintained and deprecated) https://code.google.com/p/httpclientandroidlib/

More info on the topic, see:
https://issues.apache.org/jira/browse/HTTPCLIENT-1632
https://stackoverflow.com/questions/32178854/android-api-23-httpclient-4-x-repackaged

@griffins
Copy link

griffins commented Sep 2, 2015

I look at it tomorrow. Probably ill have an idea on wat to try after that.
Its 9pm here!

On Wed, 2 Sep 2015 21:00 Marek Sebera notifications@github.com wrote:

@griffins https://github.com/Griffins I'm assigned but I don't have the
time to fix all this right now.
If you're willing to contribute and do some research, would be great to
provide script to repackage production version of HttpClient-4.X, which is
main issue we're solving right now.

There are good HttpUrlConnections based async http requesting libraries
out there, but this one was and will be based on HttpClient, no need to do
just another library like those.

We need to have JAR of Apache HttpClient components (all of them) but not
under org.apache, as that would cause classpath conflicts, but under
different namespace (such as com.loopj.httpclient)

Something like that was done previously, see HttpClientAndroidLib project
(now unmaintained and deprecated)
https://code.google.com/p/httpclientandroidlib/

More info on the topic, see:
https://issues.apache.org/jira/browse/HTTPCLIENT-1632

https://stackoverflow.com/questions/32178854/android-api-23-httpclient-4-x-repackaged


Reply to this email directly or view it on GitHub
#830 (comment)
.

@kjkrum
Copy link

kjkrum commented Sep 2, 2015

Again, this library CANNOT be ported to use HttpUrlConnection because it exposes its use of Apache HTTP through things like exceptions and method parameters. A port could never be made backward-compatible. It could be conceptually similar, but it would be a different library.

@smarek
Copy link
Member

smarek commented Sep 7, 2015

@griffins so I have it working, see repository here:
https://github.com/smarek/httpclient-android/

Currently requesting artifact group and id on Sonatype Nexus repository, and I'll push updated android-async-http library with this as dependency, instead of HC teams repackaged version or useLibrary hack

request has been placed in OSSRH-17531 https://issues.sonatype.org/browse/OSSRH-17531

@jeremylan
Copy link

@smarek Any idea on when the updated android-async-http library with this change will be released?

Thanks so much for all the help and work with this great library.

@smarek
Copy link
Member

smarek commented Sep 11, 2015

@jeremylan I should be able to do it through the weekend, there are changes needed to be done along using 4.3.3 upstream HttpClient, before the release is feasible.

@jeremylan
Copy link

@smarek Thanks heaps for the reply and all the work. All the best.

@TylerMcCraw
Copy link

Thanks @smarek!

@smarek
Copy link
Member

smarek commented Sep 12, 2015

So now we're officially running on stable upstream HttpClient 4.3.3 version, repackaged and published on Maven through group+artifact cz.msebera.android:httpclient:4.3.3, see the build script repository for reference https://github.com/smarek/httpclient-android

Code was updated to new dependency, and all tests run smoothly, compiled against latest Android SDK 23, see commit for reference 15f9556

To convert your current code, simple solution is to use sed to replace org.apache.http links with cz.msebera.android.httpclient
Sample find+sed command is

# Use `gsed -i` for OS X environment with gnu-sed installed from Homebrew or similar repository
find . -name '*.java' -exec sed -i 's/org.apache.http/cz.msebera.android.httpclient/g' \{\} +

Sincerely we're not allowed to publish to maven under org.apache group prefix, and we cannot use org.apache group in published archives, because of possible clash of classpaths on Android systems, so this is the only downside with the current solution.

I've just uploaded new 1.4.9-SNAPSHOT into staging repository, see https://oss.sonatype.org/content/repositories/snapshots/com/loopj/android/android-async-http/1.4.9-SNAPSHOT/
Read on how to add snapshot version to your project in README.md

For those who'll be testing build from source, there is also fix to get correct javadocs generated on project, see a5399d8 for reference

Please all of you, who watch this ticket, try this snapshot, and I'll solve some issues along the way on the 1.4.9 release, before publishing the non-SNAPSHOT version into central.

@jeremylan
Copy link

Hi @smarek I just tested the 1.4.9 snapshot with my code, compiled with API 23 and running in API 19 and API 23 emulators.

It all seems to work OK, thank you!

@smarek
Copy link
Member

smarek commented Sep 14, 2015

Cool, can anybody else please confirm this finds? Also I'd be greatful for tests done on API3-API10 (as we still declare the compatibility), if anybody is willing to do that.

@LaurieScheepers
Copy link

Used the 1.4.9 snapshot and replaced the necessary imports and can confirm it works

@Saren-Arterius
Copy link

same as @LaurieScheepers, it works.

@smarek smarek modified the milestones: 1.4.9, 1.5.0 Sep 19, 2015
@smarek
Copy link
Member

smarek commented Sep 19, 2015

Heads up, I've just released 1.4.9 to Maven Central repository, updated master branch with latest code, uploaded new javadocs, updated readmes with new version.

Also we're now sitting on top of HttpClent 4.3.6 ( https://github.com/smarek/httpclient-android/releases/v4.3.6 ), which already includes HttpClient-Cache and HttpMime libraries of same version, so you can drop the external dependencies, if you're using any.

1.5.0 built on top of upstream 4.3+ (hopefully we'll manage to get to 4.4+ or even 4.5+) has a lot of issues to be solved, so I'd welcome any help on updating the library according to our options, now since we're not relying on Android provided HttpClient anymore.

1.4.9 will remain as LTS version, and I plan to upload minor revisions, however no big changes will get merged into 1.4.9.X versions

Thank you all for your contribution.

@smarek smarek closed this as completed Sep 19, 2015
@LaurieScheepers
Copy link

@smarek awesome, I'll update to the new official version tomorrow. Thanks 👍

@jeremylan
Copy link

Great work @smarek !!

@Zapnologica
Copy link

@smarek Thank you so much for 1.4.9 you saved my but and a whole lot of time.

@panxw
Copy link

panxw commented Oct 20, 2015

I made one base on Android Volley, no HttpClient(apache http) need now!
https://github.com/panxw/android-volley-hurlstack

@bytebeats
Copy link

@panxw Bad idea to set Android API 14+

@panxw
Copy link

panxw commented Oct 20, 2015

@LittlePanpc It's Android API 9+ ok now!

@smarek
Copy link
Member

smarek commented Oct 26, 2015

@panxw good for you, closing for Off Topic discussion reasons

@android-async-http android-async-http locked and limited conversation to collaborators Oct 26, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests