java - How to use the legacy Apache HTTP client on Android Marshmallow? -


background

on android marshmallow, google has removed support of apache http client (link here) because doesn't have performance compared alternatives.

this might cause many apps crashing on android marshmallow.

the problem

google allows still use api, not built in one, adding line gradle file:

uselibrary 'org.apache.http.legacy' 

so, did:

dependencies {     classpath 'com.android.tools.build:gradle:1.3.0' } 

and:

android {     compilesdkversion 'android-mnc'     buildtoolsversion "23.0.0 rc3"     uselibrary 'org.apache.http.legacy'      defaultconfig {         applicationid "com.example.user.androidmtest"         minsdkversion 'mnc'         targetsdkversion 'mnc'         versioncode 1         versionname "1.0"     } 

when tried it, compiled fine (no errors being shown, , run proof-of-concept app, doesn't have special code), when tried using of classes know part of old api (like "httpclient" class), see doesn't allow me so.

i know it's not recommended use solution, must have app ready work there @ least temporarily, till work 100% on of things should change android marshmallow, , don't want surprises in form of crashes.

here's screenshot:

enter image description here

the question

why occur? did use correctly?


edit: reported issue here:

https://code.google.com/p/android/issues/detail?id=181474

android studio complaining org.apache.http classes like

org.apache.http.namevaluepair org.apache.http.client.utils.urlencodedutils 

were missing.

so added org.apache.http.legacy.jar in android/sdk/platforms/android-23/optional folder to app/libs

i added line app.gradle file

compile files('libs/org.apache.http.legacy.jar') 

but if you're using more libraries, can use way

compile filetree(dir: 'libs', include: ['*.jar']) 

this resolved errors caused because google removed support of apache http client.


Comments

Popular posts from this blog

yii2 - Yii 2 Running a Cron in the basic template -

asp.net - 'System.Web.HttpContext' does not contain a definition for 'GetOwinContext' Mystery -

c# - MSDN OneNote Api: Navigate to never before opened page without opening a OneNote Application Window -