2

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' } 
1
  • @pRaNaY sry. check the edit. it was there. Another one of trials suggested was to remove the useLibrary and just keep the compile. That failed too. that's why it was missing. Commented Sep 29, 2016 at 3:11

3 Answers 3

1

For me I use this and it work:

android { useLibrary 'org.apache.http.legacy' // put it in here compileSdkVersion 23 buildToolsVersion "23.0.2" 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' } } } 
Sign up to request clarification or add additional context in comments.

6 Comments

I was able to get rid of the error from gradle. However, the classes using Apache are still not readable, the import statements are not working. so, its more like the library wasn't loaded properly.
Can you try to validate caches and restart your android studio? Am I right? you are using android studio?
Can you explain what do you mean by validate caches please? And only the apache classes are still throwing the errors. Others are fine.
I will post it in another question, now that this warning is solved.
@LakshmiNarayanan have you solved error or not? and compile your project?
|
1

First of all make sure to use this gradle plugin or higher:

classpath 'com.android.tools.build:gradle:1.3.1' 

Then check if the Android/Sdk/platforms/android-23/optional folder contains the optional.json file.

A good idea is to use the latest version :

classpath 'com.android.tools.build:gradle:2.2.0' 

Without this version you will not able to handle with the useLibrary 'org.apache.http.legacy'

It is non related with your issue, but also check your dependencies and the api used to compile.

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

Comments

0

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.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.