2

In android studio in mainactivity at the top I have the lines

import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.util.EncodingUtils;

Cannot resolve symbol of HttpClient HttpPost and EncodingUtils All this marked in red.

If I remember right my project when created it was targeting api 15. My device to run it later on is lg g3.

Also I installed android studio yesterday and inside the android studio I didn't checked and installed the AVD manager packages not sure if I should or they are already installed.

This is what I see when going to AVD I see there also something Failed to load on the right top corner.

AVD

Daniel Voit
  • 111
  • 1
  • 10
  • Possible duplicate of [Android deprecated apache module (HttpClient, HttpResponse, etc.)](http://stackoverflow.com/questions/29294479/android-deprecated-apache-module-httpclient-httpresponse-etc) – e4c5 May 11 '16 at 05:46

3 Answers3

3

You need to add this inside Build.Gradle android.

android {
    compileSdkVersion 23
    buildToolsVersion '22.0.1'

    useLibrary 'org.apache.http.legacy'
}

Also add this to Dependencies.

compile 'org.jbundle.util.osgi.wrapped:org.jbundle.util.osgi.wrapped.org.apache.http.client:4.1.2'
Jay Rathod
  • 11,131
  • 6
  • 34
  • 58
1

Apache HttpClient has been deprecated and removed from Android 6 onwards as per this announcement. You should not be using it.

The recommended way now is to use HttpUrlConnection.

OR, switch to OkHttp.

Both of these are said to be much efficient than the legacy HttpClient.

S.D.
  • 29,290
  • 3
  • 79
  • 130
0

As android removed apache libraries , you need to add those libraries yourself

to add follow these steps

1 ) download Apache HttpClient and HttpCore jar files (you can get here link)

2) copy the jar files and paste it in libs folder of your application. 3) right click on your app folder and open module setting.select dependencies tab

4)click green + button and selectFile dependency and then select your jar file. and click on dropdown and select that as "Compile"

5)if you get any error while building gradle.(Duplicate files Exception)

add this lines to build

packagingOptions {
exclude 'META-INF/DEPENDENCIES.txt'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/NOTICE'
}
Jayanth
  • 5,954
  • 3
  • 21
  • 38