Gradle failed to sync with 'unable to find optional library'

前端 未结 9 2374
刺人心
刺人心 2020-12-01 18:24

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


        
相关标签:
9条回答
  • 2020-12-01 18:59

    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:

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

    Creating a new JSON file with with above content solved the problem for me.

    0 讨论(0)
  • 2020-12-01 19:01

    Top level build.gradle - /build.gradle

    buildscript {
    ...
    dependencies {
        classpath 'com.android.tools.build:gradle:1.3.1'
    }
    }
    

    Module specific build.gradle - /app/build.gradle

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

    Add org.apache.http.legacy.jar which is in Android/Sdk/platforms/android-23/optional folder to app/libs directory and sync your project

    0 讨论(0)
  • 2020-12-01 19:03

    You need to add org.apache.http.legacy.jar jar file in your Android Stuido project's app/libs folder.

      Jar Location - `<SDK LOCATION>\android-sdk\platforms\android-23\optional`  
    

    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 File

    Module:app

    android {
    compileSdkVersion 'Google Inc.:Google APIs:23'
    buildToolsVersion "24.0.0"
    defaultConfig {
        applicationId "<ur_app_id>"
        minSdkVersion 15
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    }
    
    0 讨论(0)
  • 2020-12-01 19:06

    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.

    0 讨论(0)
  • 2020-12-01 19:07

    if above solution is not work then try this way

    I experienced this problem recently, and it is caused by the path length restriction I think it´s 256 characters maximum.

    Relocate your Project and the build will succeed.

    0 讨论(0)
  • 2020-12-01 19:08

    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.

    0 讨论(0)
提交回复
热议问题