摇篮失败,同步'无法找到任意库“ [英] Gradle failed to sync with 'unable to find optional library'

查看:204
本文介绍了摇篮失败,同步'无法找到任意库“的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

 警告:无法找到可选库:org.apache.http.legacy

我的gradle项目是:

  buildscript {
    库{
        mavenCentral()
    }
    依赖{
        类路径'com.android.tools.build:gradle:1.3.0
    }
}allprojects {
    库{
        mavenCentral()
    }
}

和我的Gradle模块:

 应用插件:'机器人'安卓{
    useLibraryorg.apache.http.legacy    compileSdkVersion 23
    buildToolsVersion '23 .0.2
    defaultConfig {
        16的minSdkVersion
        targetSdkVersion 23
    }
    buildTypes {
        发布 {
        }
    }
    productFlavors {
    }
}依赖{
    编译文件树(包括:['的* .jar'],DIR:库)
    编译com.android.support:support-v4:23.1.1
    编译com.android.support:appcompat-v7:23.1.1
}

<一个href=\"http://developer.android.com/about/versions/marshmallow/android-6.0-changes.html#behavior-apache-http-client\"相对=nofollow>从谷歌文档:


  

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

 安卓{
    useLibraryorg.apache.http.legacy
}


我试过的建议在<一提href=\"http://stackoverflow.com/questions/31653002/how-to-use-the-legacy-apache-http-client-on-android-m\">this螺纹但他们不工作。相同的结果,与Android 1.5的工作室和2 preVIEW。

我该如何解决这个问题?

修改:事情到目前为止,我已经试过:


  1. 更改类路径的Gradle版本1.3.0,1.3.1,1.5.0。


  2. 从23.0.1更改 compileSdkVersion targetSdkVersion 来22.在buildToolsVersion,23.0。 0,22.0.1。



解决方案

顶级的build.gradle - /build.gradle

  buildscript {
...
依赖{
    类路径'com.android.tools.build:gradle:1.3.1
}
}

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

 安卓{
compileSdkVersion 23
buildToolsVersion23.0.0
useLibraryorg.apache.http.legacy
...
}

添加org.apache.http.legacy.jar这是在的Andr​​oid / SDK /平台/ Android的23 /可选文件夹应用/库目录,并同步您的项目

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

My project gradle is:

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

allprojects {
    repositories {
        mavenCentral()
    }
}

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'
}

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'
}

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. Change gradle classpath versions to 1.3.0, 1.3.1, 1.5.0.

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

解决方案

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

这篇关于摇篮失败,同步'无法找到任意库“的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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