android - Gradle 无法与 'unable to find optional library' 同步

标签 android android-studio gradle build.gradle

我不得不重新安装我的系统,今天当我尝试与 gradle 同步时,我在 Android Studio 中遇到了这个错误:

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

我的项目等级是:

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:1.3.0'
    }
}

allprojects {
    repositories {
        mavenCentral()
    }
}

还有我的模块 gradle:

apply plugin: 'android'

android {
    useLibrary  'org.apache.http.legacy'

    compileSdkVersion 23
    buildToolsVersion '23.0.2'
    defaultConfig {
        minSdkVersion 16
        targetSdkVersion 23
    }
    buildTypes {
        release {
        }
    }
    productFlavors {
    }
}

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

From the google docs :

To continue using the Apache HTTP APIs, you must first declare the following compile-time dependency in your build.gradle file:

android {
    useLibrary 'org.apache.http.legacy'
}

我尝试了 this thread 中提到的建议但他们不工作。与 android studio 1.5 和 2 预览版结果相同。

我该如何解决这个问题?

编辑:到目前为止我尝试过的事情:

  1. 将 gradle 类路径版本更改为 1.3.0、1.3.1、1.5.0。

  2. compileSdkVersiontargetSdkVersion 更改为 22。还将 buildToolsVersion 从 23.0.1、23.0.0、22.0.1 更改。

最佳答案

顶级 build.gradle -/build.gradle

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

模块特定的 build.gradle -/app/build.gradle

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

Android/Sdk/platforms/android-23/optional 文件夹中的 org.apache.http.legacy.jar 添加到 app/libs 目录并同步您的项目

关于android - Gradle 无法与 'unable to find optional library' 同步,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33914589/

相关文章:

java - Android Studio 无法解析方法 getBaseContext(),但它曾经可以工作

Android 构建失败 : error: cannot find symbol variable radio_animator

gradle - 在执行多个“compile…”任务之前先连接generateSrc gradle任务

java - 如何为特定的 Jenkins 工作设置 `killSoftly`?

android - 如何在没有 root 权限的情况下以编程方式截取其他应用程序的屏幕截图,例如 Screenshot UX Trial?

android - 如何在不划分android中的ActivityScreen的情况下实现多个 ListView

android - 除了 sdk 之外,如何安装以前版本的构建工具?

java - 使用 gradle 编译 zip,包括由同级子项目实现的库

iphone - 是否可以将多个纹理映射到 openGL ES 中的一个形状上?

android - 从相机预览问题中获取的位图中读取像素