6

First sorry for my bad English I am new to android studio 1.4 ,I am getting error in HttpClient

Error

C:\Users\madhu\AndroidStudioProjects\LoginAndsign\app\src\main\java\com\login\loginandsign\SimpleHttpClient.java

Error:(27, 20) error: cannot find symbol class HttpClient

Error:(34, 20) error: cannot find symbol class HttpClient

Error:(36, 31) error: cannot find symbol class DefaultHttpClient

Error:(40, 13) error: cannot find symbol variable ConnManagerParams


Error:(57, 13) error: cannot find symbol class HttpClient

Error:(58, 13) error: cannot find symbol class HttpPost

Error:(58, 36) error: cannot find symbol class HttpPost

Error:(59, 13) error: cannot find symbol class UrlEncodedFormEntity

Error:(59, 51) error: cannot find symbol class UrlEncodedFormEntity

Error:(96, 13) error: cannot find symbol class HttpClient

Error:(97, 13) error: cannot find symbol class HttpGet

Error:(97, 35) error: cannot find symbol class HttpGet

I added below dependency but still it showing same error

dependencies {
compile 'com.google.android.gms:play-services:+'
compile 'org.apache.httpcomponents:httpclient:4.2.6'
compile 'org.apache.httpcomponents:httpmime:4.2.6'
compile files('libs/core.jar')
}
Abhinav singh
  • 1,448
  • 1
  • 14
  • 31
pramod K
  • 101
  • 1
  • 4

6 Answers6

3

HttpClient was removed in Android 6.0.

To continue using HttpClient, add code below to your build.gradle:

 android{
    compileSdkVersion 23
    buildToolsVersion '23.0.1'
    useLibrary  'org.apache.http.legacy'
}
Sufian
  • 6,405
  • 16
  • 66
  • 120
Mohd Asif Ahmed
  • 1,880
  • 2
  • 15
  • 29
3

You need to initialize useLibrary 'org.apache.http.legacy'

Please check HttpClient won't import in Android Studio

android {
    compileSdkVersion 23
    buildToolsVersion '23.0.1' 


    defaultConfig {
        minSdkVersion // set yours 
        targetSdkVersion 23
        versionCode 11 //Yours
        versionName "0.1" // Yours
    }

dependencies {
compile 'com.google.android.gms:play-services:7.8.0'
compile 'org.apache.httpcomponents:httpmime:4.2.6'
compile 'org.apache.httpcomponents:httpclient:4.5'
compile files('libs/core.jar')
}

Then Clean-Rebuild-Restart-Sync Your Project .

Community
  • 1
  • 1
IntelliJ Amiya
  • 74,896
  • 15
  • 165
  • 198
2

Just add this line in dependencies

 compile 'org.jbundle.util.osgi.wrapped:org.jbundle.util.osgi.wrapped.org.apache.http.client:4.1.2'
Aditya Vyas-Lakhan
  • 13,409
  • 16
  • 61
  • 96
2

might be you didn't upgrade your gradle plugin in root build.gradle file.

dependencies {
        classpath 'com.android.tools.build:gradle:1.5.0' 
        // Lowest version for useLibrary is 1.3.0
        // Android Studio will notify you about the latest stable version
        // See all versions: http://jcenter.bintray.com/com/android/tools/build/gradle/
    }
Bhavesh Patadiya
  • 25,740
  • 15
  • 81
  • 107
1

if you are using target sdk as 23 add below code in your build.grade Module specific build.gradle - /app/build.gradle

android {
    compileSdkVersion 23
     buildToolsVersion "23.0.0"
     useLibrary 'org.apache.http.legacy'
     ...
       }

and change your buildscript to
**Top level build.gradle - /build.gradle**

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

For More Information please check this android dev link

Prags
  • 2,457
  • 2
  • 21
  • 38
  • where i need to put classpath 'com.android.tools.build:gradle:1.3.0' line please tell me @Er Pragati Singh – pramod K Jan 28 '16 at 05:45
  • after doing that i am getting this error Warning:Unable to find optional library: org.apache.http.legacy @Er Pragati Singh – pramod K Jan 28 '16 at 05:50
  • just reinstall API 23 (remove and install again). – Prags Jan 28 '16 at 05:52
  • please check hope it help you [link](http://stackoverflow.com/questions/33914589/gradle-failed-to-sync-with-unable-to-find-optional-library) – Prags Jan 28 '16 at 06:02
  • how to reinstall Api 23 in android studio – pramod K Jan 28 '16 at 06:13
  • go to SDK like in mac /Users/user/Library/Android/sdk or select project and click **FILE MENU -> PROJECT STRUCTURE** you will found SDK location and check above link just click in link – Prags Jan 28 '16 at 06:26
0

If you have already added library and recompiled but still not working then

Check if you have android-sdk-windows\platforms\android-23\optional\optional.json in the particular place.

If not then just remove API 23 and install that again, that will work.

Shree Krishna
  • 8,474
  • 6
  • 40
  • 68