Why Warning:Unable to find optional library: org.apache.http.legacy occurs?
Asked Answered
R

6

32

My gradle file:

apply plugin: 'com.android.application' 

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

  defaultConfig { 
    applicationId "com.skripsi.irwanto.paud" 
    minSdkVersion 15 
    targetSdkVersion 23 
    versionCode 1 
    versionName "1.0" 
  } 

  buildTypes { 
    release { 
      minifyEnabled false 
      proguardFiles getDefaultProauardFile('proguard-android.txt'), 'proguard-rules.pro' 
    } 
  } 
} 
dependencies { 
 compile fileTree(include: ['*.jar'], dir: 'libs') 
 testCompile 'junit:junit:4.12' 
 compile 'com.android.support:appcompat-v7:23.1.11 
} 

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

Rillings answered 24/11, 2015 at 16:26 Comment(2)
Your code is an image... of the build.gradle? Hmmm. No. It doesn't work like that. Post your code and your logcat in their text form.Dungdungan
for me i removed this line (useLibrary 'org.apache.http.legacy') and changed my target SDK to 22Nicholle
E
79

I guess, the easier way to solve this issue without having to reinstall the SDK is to create a file called optional.json in <sdk-path>\platforms\android-23\optional\ directory with the following content:

[
  {
    "name": "org.apache.http.legacy",
    "jar": "org.apache.http.legacy.jar",
    "manifest": false
  }
]

It solved the problem for me.


EDIT: Information taken from @domoch's answer below on how to locate your SDK location

To Locate your Android SDK's Location

Go to Android Studio Settings -> Appearence & Behavior -> System Settings and look for Android SDK Location. In Windows, it usually would be pointing to C:\Users\<username>\AppData\Local\Android\sdk.

Essex answered 28/11, 2015 at 10:13 Comment(13)
This did not solved the problem for me. I still have the warning and the project does not compileBurris
Do you have more than one SDK versions installed? Are you updating the correct folder?Essex
one sdk version installed, a have copied http.legacy.jar to libs and i still get the errorBurris
@ventura8: Maybe trying to reinstall Android Studio with a new SDK might be the solution for you. Have you tried that?Essex
make sure you have compileSDKVersion set to 23Gatian
i have reinstalled android studio and android sdk and i still get that errorBurris
@Burris do you see the JSON file in that directory AND the jar file there? Does the JSON file have the contents like above? Is your Android Studio using the reinstalled SDK?Essex
I see the json file and the jar file. the json file has the content from above. My Android studio is using the reinstalled sdk. it still does not compile. i am baffledBurris
@ventura8: Did you get it working? I am also facing same issueEzar
@SagarTrehan nope. not yet. really hopping somebody with more experience looks at this.Burris
@Burris did you get it? Am sitting over the same issue for over 10 hours!Insalivate
@LakshmiNarayanan i did not get it. i still am unable to compile.Burris
At the risk of stating the obvious (and being aware I'm posting this to a thread where android-28 didn't exist at the time...): This indeed also happens in android-28, and the same fix applies.Arteaga
H
27

I had exactly the same issue. Please check if you have android-sdk-windows\platforms\android-23\optional\optional.json file in place. If not then just reinstall API 23 (remove and install again).

Hasdrubal answered 25/11, 2015 at 11:4 Comment(2)
This worked for me! From a fresh install of Android Studio with a new SDK this file appeared to be missing. It was still missing after updating all of the API 23 packages. Deleting all the API 23 packages and re-installing worked.Neckline
Well, I'm not going to question why that file disappeared but thanks!Inoperable
N
3

Why? If you use Android Studio on Windows then optional.json file should be not only in \Program Files (x86)\...\platforms\android-23\optional\ .

So: go to Android Studio Settings -> Appearence & Behavior -> System Settings and look for Android SDK Location, copy (or create) optional.json in corresponding folder. Or just edit Android SDK Location to \Program Files (x86)\...

In my case Android SDK Location was C:\Users\Usernade\AppData\Local\Android\sdk and there was no optional.json file.

North answered 4/2, 2016 at 12:29 Comment(0)
P
1
  1. Settings -> Appearence & Behavior -> System Settings and look for Android SDK Location

  2. platforms/Android 23/optional/

  3. org.apache.http.legacy jar file is copy and paste your android studio project lib and this jar file gradle compile files('libs/org.apache.http.legacy.jar')

Pyrography answered 14/3, 2016 at 4:15 Comment(0)
K
0

The error is that the optional.json file is not in the <sdk-path>\platforms\android-23\optional\ folder.

I solved this by the following:

  1. Go to the sdk manager
  2. Select Android Sdk and updates are available in the Appropriate API level.
  3. Just update it.
Katelynnkaterina answered 18/9, 2016 at 6:45 Comment(0)
D
0

I know this is pretty ol' one. However, if any1 sees this and wonders what else can be done. Than go and check whether the SDK path is set in Env Vars. Because the path might be using anything like this "$(ANDROID_HOME)".

Duvalier answered 24/5, 2023 at 12:7 Comment(1)
Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.Blackandblue

© 2022 - 2024 — McMap. All rights reserved.