1

When I try to sync gradle, it shows this error.

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

My build.gradle:

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

defaultConfig {
    applicationId "com.myapp.mynamespace"
    minSdkVersion 15
    targetSdkVersion 23
    versionCode 17
    versionName "1.7"
    multiDexEnabled true
}

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

   compileOptions.encoding = 'UTF-8'
}

My root build.gradle:

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:1.3.0'
    }
}

allprojects {
    repositories {
        jcenter()
    }
}

I tried to use gradle 1.3.1 and buildToolsVersion 23.0.2 but it didn't work. There aren't many questions like this and they didn't resolved out. So I needed to ask this question to come to a fine end.

Egemen Hamutçu
  • 1,602
  • 3
  • 22
  • 34
  • Follow this link http://stackoverflow.com/questions/31653002/how-to-use-the-legacy-apache-http-client-on-android-m. – Long Phan Nov 25 '15 at 09:09
  • @LongPhan that does not work. – Daniel Nov 25 '15 at 10:12
  • I also have this issue and fixed it by removing the line `useLibrary 'org.apache.http.legacy'` from the module `build.gradle`. Give that a try. If not, try some of the suggestions [here](http://stackoverflow.com/questions/33914589/gradle-failed-to-sync-with-unable-to-find-optional-library). Good luck! – Daniel Nov 25 '15 at 11:39
  • It didn't work. I need 'org.apache.http.legacy' in my project. This is really a Android Studio bug, because all of my collegues have the same project that is working fine in their computers. – Egemen Hamutçu Nov 26 '15 at 09:17

1 Answers1

0

I had this problem before and the way I solved it was by copying the JAR into the libs/ folder of your project, Gradle will not resolve this jar automatically.

You should have a copy in your local machine already under SDK/platforms/android-23/optional

Chinesco
  • 78
  • 1
  • 7
  • I have to accept this answer because this is not the exact solution, it is a workaround. This is an absulately Gradle bug and needs to be solved. – Egemen Hamutçu Dec 15 '15 at 08:39