我不得不重新安装我的系统,今天当我尝试与 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'
}
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 预览版结果相同。
我该如何解决这个问题?
编辑:到目前为止我尝试过的事情:
将 gradle 类路径版本更改为 1.3.0、1.3.1、1.5.0。
将
compileSdkVersion
和targetSdkVersion
更改为 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/