Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Apache HTTP connection with Android 6.0 (Marshmallow)

Is there is any way to include the Apache library directly in Gradle to make it work with Android 6.0 ?

I've tried to include the libraries like that:

compile 'org.apache.httpcomponents:httpcore:4.4.1'
compile 'org.apache.httpcomponents:httpclient:4.5'

And Android Studio couldn't manage to find the following import:

import org.apache.http.auth.AuthenticationException;
import org.apache.http.auth.Credentials;
import org.apache.http.auth.MalformedChallengeException;
import org.apache.http.auth.UsernamePasswordCredentials;
import org.apache.http.impl.auth.DigestScheme;
like image 472
Hrk Avatar asked Aug 18 '15 11:08

Hrk


2 Answers

This page discusses the removal of the Apache HTTP classes, and it suggests a workaround as well:

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'
   }

In my case Android Studio still complained that it couldn't find these classes, but the app did build and run.

The page does recommend you move to HttpURLConnection, though.

like image 185
benvd Avatar answered Oct 31 '22 15:10

benvd


According to the API 22-23 diff changes, the org.apache.http.* packages have been removed as of Android 6.0 (Marshmallow) API Level 23.

http://developer.android.com/sdk/api_diff/23/changes.html

via : http://android-developers.blogspot.co.uk/2015/08/m-developer-preview-3-final-sdk.html

like image 27
Kosso Avatar answered Oct 31 '22 14:10

Kosso