MEZesUBI
MEZesUBI

Reputation: 307

App won't build with error Unable to find optional library

I clean reinstalled Android Studio, as I'm working on a project with some colleagues. We have a successfully buildable, runnable project, which unfortunately does not build on my computer. Freshly cloned from our online repo, it always gives me the following warning and error at build:

Warning:Unable to find optional library: org.apache.http.legacy Error:A problem occurred configuring project ':app'. > Unable to find optional library: org.apache.http.legacy

I have no idea how to fix it, as I'm new to Android Developement and it's funny to me that it works on my coulleagues PCs and not on mine.

In the build.gradle (Module: app) file I have the rows

useLibrary  'org.apache.http.legacy'

so I really am curious why the app does not build.

Upvotes: 2

Views: 6016

Answers (2)

MEZesUBI
MEZesUBI

Reputation: 307

Found out that I was lacking an Optional.json file from the path

AppData\Local\Android\sdk1\platforms\android-23\optional

For anyone bumping in the same error, could try checking if the path has the library.java files and the Optional.json file with all the optional libraries set, like this

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

Upvotes: 8

Daniel Netzer
Daniel Netzer

Reputation: 2232

well according to Android since API level 23 apache have been deprecated, https://developer.android.com/about/versions/android-5.1.html#http, I recommend using Volley. http://developer.android.com/training/volley/index.html

Edited :

you need to select a different API level i believe that if you'll choose API level 21 it should run easily, in the build.gradle file change the following according to what works for your project.

apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.1"

    defaultConfig {
        applicationId "com.stackoverflow.answer"
        minSdkVersion 16
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
    }

in the lines with the --compileSdkVersion change it to 21 change the ToolsVersion accordingly

and on targetSdkVersion change to 21 aswell. once done editing Sync the gradle.buid and the recompile.

let me know if that works as I know it should.

Upvotes: 1

Related Questions