irwan
irwan

Reputation: 329

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

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

Upvotes: 32

Views: 42641

Answers (6)

Simon Tomek
Simon Tomek

Reputation: 1

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)".

Upvotes: 0

Ratheesh Maithadam
Ratheesh Maithadam

Reputation: 1

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.

Upvotes: 0

Kamlesh Lakhani
Kamlesh Lakhani

Reputation: 87

  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')

Upvotes: 1

Vite Falcon
Vite Falcon

Reputation: 6645

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.

Upvotes: 79

Domoch
Domoch

Reputation: 81

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.

Upvotes: 3

pratt
pratt

Reputation: 1813

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).

Upvotes: 27

Related Questions