Gradle 无法与“无法找到可选库"同步 [英] Gradle failed to sync with 'unable to find optional library'

查看:25
本文介绍了Gradle 无法与“无法找到可选库"同步的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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.apache.http.legacy

我的项目gradle是:

My project gradle is:

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

allprojects {
    repositories {
        mavenCentral()
    }
}

还有我的模块gradle:

And my module 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'
}

来自谷歌文档:

要继续使用 Apache HTTP API,您必须首先声明以下是 build.gradle 文件中的编译时依赖项:

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 中提到的建议线程 但它们不起作用.与 android studio 1.5 和 2 预览版的结果相同.

I tried the suggestions mention in this thread but they don't work. Same result with android studio 1.5 and 2 preview.

我该如何解决这个问题?

How can I fix this?

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

Edit: Things I've tried so far:

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

  1. Change gradle classpath versions to 1.3.0, 1.3.1, 1.5.0.

compileSdkVersiontargetSdkVersion 更改为 22.还有 23.0.1、23.0.0、22.0.1 的 buildToolsVersion.

Change the compileSdkVersion and targetSdkVersion to 22. Also the buildToolsVersion from 23.0.1, 23.0.0, 22.0.1.

推荐答案

顶级 build.gradle -/build.gradle

Top level build.gradle - /build.gradle

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

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

Module specific 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 目录并同步您的项目

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

这篇关于Gradle 无法与“无法找到可选库"同步的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆