I had to reinstall my system and today I get this error in Android Studio when I try to sync with gradle:
Warning: Unable to find optional library: org.apache.http.legacy
My project gradle is:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.3.0'
}
}
allprojects {
repositories {
mavenCentral()
}
}
And my module gradle:
apply plugin: 'android'
android {
useLibrary 'org.apache.http.legacy'
compileSdkVersion 23
buildToolsVersion '23.0.2'
defaultConfig {
minSdkVersion 16
targetSdkVersion 23
}
buildTypes {
release {
}
}
productFlavors {
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:support-v4:23.1.1'
compile 'com.android.support:appcompat-v7:23.1.1'
}
To continue using the Apache HTTP APIs, you must first declare the following compile-time dependency in your build.gradle file:
android { useLibrary 'org.apache.http.legacy' }
I tried the suggestions mention in this thread but they don't work. Same result with android studio 1.5 and 2 preview.
How can I fix this?
Edit: Things I've tried so far:
Change gradle classpath versions to 1.3.0, 1.3.1, 1.5.0.
Change the
compileSdkVersion
andtargetSdkVersion
to 22. Also the buildToolsVersion from 23.0.1, 23.0.0, 22.0.1.
You need to add
org.apache.http.legacy.jar
jar file in your Android Stuido project's app/libs folder.To do this, just right click on your project and select
Show in Explorer
then go to...\app\libs
and paste above jar file and Sync your Project with Gradle FileModule:app
Update your project gradle file to use gradle version 1.3.1.
Also try adding codehause repo.
In my case the problem was actually occurring because I didn't have the correct SDK installed on that computer. Navigating to
.../Android/Sdk/platforms/android-23
I could see that folder was empty. Adding SDK 23 via the SDK manager fixed the problem and allowed me to compile.You should manually check that you have the same version of the SDK installed that is specified under
compileSdkVersion
in your build.gradle file.In my case, it didn't work because I was missing
optional.json
in<sdk-path>\platforms\android-23\optional\
, directory with the following content:Creating a new JSON file with with above content solved the problem for me.
After a lot of working this solutions work for me . ** Studio\Android\sdk\platforms** here delete your android-23 and from sdk manager update api 23 again.** . it will solve your issue.