【问题标题】:Android Studio: Error:Unable to find optional library: org.apache.http.legacyAndroid Studio:错误:找不到可选库:org.apache.http.legacy
【发布时间】:2016-10-21 22:53:30
【问题描述】:

我知道这个问题在这里出现了很多次。我尝试了所有解决方案。我有一个应用程序的源代码。我想构建它,但出现此错误:Error:Unable to find optional library: org.apache.http.legacy

这是 build.gradle (Module app) 的一部分

apply plugin: 'com.android.application'

android {
    compileSdkVersion 21
    buildToolsVersion '21.1.2'

    dexOptions {
        javaMaxHeapSize "4g"
    }

    useLibrary 'org.apache.http.legacy'

    defaultConfig {
        applicationId "com.sensiblewallet"
        minSdkVersion 16
        targetSdkVersion 21
        multiDexEnabled true
    }

    signingConfigs {
        release {
            storeFile file("android.keystore")
            storePassword "123456"
            keyAlias "sensiblewallet"
            keyPassword "123456"
        }
    }

    buildTypes {
        release {
            //minifyEnabled false
            //proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
            //signingConfig signingConfigs.release
            //multiDexEnabled true
        }
    }
}

这里是build.gradle(项目)

// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.2.1'
    }
}

allprojects {
    repositories {
        jcenter()
    }
}

我什么都试过了……怎么了?请帮助我,非常感谢!

【问题讨论】:

  • compileSdkVersion 为 21,我认为您不需要 useLibrary 'org.apache.http.legacy'。在将 compileSdkVersion 设置为 23 或更高之前,这不是必需的。所以,你可以注释掉那一行。现在,您最有可能应该将您的compileSdkVersion 设置为更高的值(最新为25),但这样做并更新您的buildToolsVersion 以匹配,可能会允许加载该库。跨度>

标签: android android-studio gradle android-gradle-plugin build.gradle


【解决方案1】:

你必须使用 API 23+:

android {
     compileSdkVersion 23
     buildToolsVersion "23.0.0"

     useLibrary 'org.apache.http.legacy'

}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-07-27
    • 1970-01-01
    • 1970-01-01
    • 2015-05-14
    • 2015-11-24
    • 2020-11-23
    • 1970-01-01
    相关资源
    最近更新 更多