【问题标题】:Android Studio - Unable to find optional library: org.apache.http.legacyAndroid Studio - 找不到可选库:org.apache.http.legacy
【发布时间】:2016-12-01 20:54:21
【问题描述】:

我正在制作一个带有导航抽屉的安卓应用。我记得我使用了一些要求sdk版本为24的功能,所以compileSdkVersion和targetSdkVersion一样需要24,但是我的android手机只有19所以我没有看到手机上下载的应用程序,它打开了一次我完成了项目的运行,但是当我关闭手机上的选项卡时,我无法再次打开它。因此,我尝试将 compileSdkVersion 和 targetSdkVersion 更改为 19,但出现此错误:无法找到可选库:org.apache.http.legacy

build.gradle:

apply plugin: 'com.android.application'

android {
compileSdkVersion 19
buildToolsVersion "25.0.0"
defaultConfig {
    applicationId "com.marivel.cruz.threatmapping"
    minSdkVersion 17
    targetSdkVersion 19
    versionCode 1
    versionName "1.0"
    testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

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

useLibrary 'org.apache.http.legacy'
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
    exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:19.+'
compile 'com.android.support:support-v4:19.1.0'
compile 'com.google.android.gms:play-services-maps:9.8.0'
compile 'com.android.support:multidex:1.0.0'
compile 'com.google.android.gms:play-services:9.8.0'
testCompile 'junit:junit:4.12'
}

【问题讨论】:

标签: android sdk


【解决方案1】:

这似乎是一种解决方法,但请尝试注释掉使用库行并在您的 gradle 构建文件的依赖项下添加以下内容:

dependencies {
compile files('libs/httpclient-4.4.jar')  
compile files('libs/httpcore-4.4.jar')
compile files('libs/httpmime-4.3.6.jar')
}

您必须从 apache 下载这些文件并将它们添加到您的 libs 目录中。这以前对我有用,但正如我所说,它感觉有点像一种解决方法。

您可以在此处找到这些 jar 文件:

Httpclient

Httpcore

Httpmime

【讨论】:

  • 对不起,我必须在网上单独下载这些文件吗?
  • @camille 您必须从 apache 下载这些文件并将它们添加到您的 libs 目录中。我已经为每个添加了指向正确下载位置的链接。让我知道它是否有效。
  • 我已将文件放在 libs 目录中并显示错误:没有此类属性:为类编译:org.gradle.api.internal.file.collections.DefaultConfigurableFileCollection
  • @camille ,这很奇怪。您是否在“compile fileTree(dir: 'libs', include: ['*.jar'])”部分下方添加了行
  • 您可以尝试使用以下依赖项从 Maven Central 获取这些:compile 'org.apache.httpcomponents:httpclient:4.5.13'compile 'org.apache.httpcomponents:httpcore:4.4.14'compile 'org.apache.httpcomponents:httpmime:4.5.13'(根据需要更改版本)。但是,这给了我关于与 Android 提供的内部版本冲突的警告。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2016-07-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-03-27
  • 2019-08-21
  • 2014-08-26
相关资源
最近更新 更多