Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Volley in Android M developer preview: org.apache.http cannot be resolved

I'm testing Volley's HurlStack in Android M Developer Preview.

After I change compileSdkVersion from 22 to 'android-MNC', all classes from org.apache.http are not compiled:

import org.apache.http.Header;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.ProtocolVersion;
import org.apache.http.StatusLine;
import org.apache.http.entity.BasicHttpEntity;
import org.apache.http.message.BasicHeader;
import org.apache.http.message.BasicHttpResponse;
import org.apache.http.message.BasicStatusLine;

How can I modify my code to solve this problem?

I know there're some changes related to Apache HTTP client, but it still doesn't work when I follow the steps to add useLibrary 'org.apache.http.legacy' in gradle.

Reference: HurlStack.java AOSP

Behavior Changes: Apache HTTP Client Removal

like image 242
Song Avatar asked Jul 10 '15 21:07

Song


2 Answers

The official “Behaviour Changes” document states that the Apache HTTP client is removed in Android M — not deprecated, but removed. Personally I highly suggest switching to OkHttp which actually is used as a HttpURLConnection engine since KitKat, by using a dependency you get all fresh goodies from Square team directly.

like image 186
Artur Dryomov Avatar answered Nov 14 '22 03:11

Artur Dryomov


You can ignore these warns, because Volley is still compiled using API 22: https://github.com/mcxiaoke/android-volley/blob/master/gradle.properties

add these in proguard configuration: -dontwarn org.apache.http.** -dontwarn com.android.volley.toolbox.**

like image 24
cn123h Avatar answered Nov 14 '22 04:11

cn123h