Search code examples
androidandroid-gradle-pluginapache-commons-httpclient

Unable to find optional library: org.apache.http.legacy


Tried everything from stackoverflow. I have listed below all that I tried to rectify this error : (I know there are lot of answers for this. It's still isn't working for me)

  1. Checked for the presence of the .json file (check)
  2. Add the "useLibrary 'org.apache.http.legacy'" to app module gradle file (check)
  3. Add the .jar file from the sdk location to libs (check)
  4. Reinstall API 23 (check)
  5. Right click the jar from libs folder and add to library (check)
  6. Change location to avoid 256 characters. (check)
  7. add "compile fileTree(dir: 'libs', include: ['*.jar'])" to gradle file dependencies (was present by default) (check)

That is pretty much everything from all the answers. Can anyone please provide a soltuion? I have been on this for 10 hours; Reinstalling and changing scripts.

My Gradle :

apply plugin: 'com.android.application'

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

    defaultConfig {
        applicationId "com.example.name"
        minSdkVersion 15
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:24.0.0-alpha1'
}

Solution

  • I was able to solve the Warning message

        Unable to find optional library: org.apache.http.legacy
    

    By upgrading my Android studio. It was 1.3.2 . Now it is 2.2.