android - 无法找到可选库 : org. apache.http.legacy

标签 android android-gradle-plugin apache-commons-httpclient

尝试了 stackoverflow 中的所有内容。我在下面列出了我尝试纠正此错误的所有内容:(我知道对此有很多答案。它仍然不适合我)

  1. 检查 .json 文件是否存在(检查)
  2. 将“useLibrary 'org.apache.http.legacy'”添加到应用模块 gradle 文件(选中)
  3. 将 .jar 文件从 sdk 位置添加到库(选中)
  4. 重新安装 API 23(选中)
  5. 右键单击 libs 文件夹中的 jar 并添加到库(选中)
  6. 更改位置以避免 256 个字符。 (检查)
  7. 将“compile fileTree(dir: 'libs', include: ['*.jar'])”添加到 gradle 文件依赖项(默认存在)(选中)

这几乎是所有答案的全部内容。有人可以提供解决方案吗?我已经在这上面花了10个小时了;重新安装和更改脚本。

我的 Gradle :

apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.2"
    useLibrary 'org.apache.http.legacy'

    defaultConfig {
        applicationId "com.example.name"
        minSdkVersion 15
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
    }

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

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:24.0.0-alpha1'
}

最佳答案

对我来说,我使用这个并且它有效:

android {
    useLibrary 'org.apache.http.legacy' // put it in here
    compileSdkVersion 23
    buildToolsVersion "23.0.2"

    defaultConfig {
        applicationId "com.example.name"
        minSdkVersion 15
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

关于android - 无法找到可选库 : org. apache.http.legacy,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39760620/

相关文章:

java - Android 在 inflated layout 时动态居中按钮

gradle - 未知主机 'downloads.gradle.org'在Android Studio中创建新项目时

java - Java 中使用 commons HttpClient 的curl 等效项

java - 在单例中使用 Apache CloseableHttpClient 的风险

android - 是否可以在 Android 中使用具有 MVP 架构的分页库?

Android - 将图像名称 "package"抛出编译时错误

Android 发布 APK 获取错误 NoSuchFieldError

java - 使用 Oauth2 和独立 java 应用程序获取访问 token

java - 将 google play services 版本添加到应用程序的 list 中会出错

java - 无法解析 com.google.android.gms play-services-auth :11. 4.0