小编典典

如何将Apache HTTP API(旧版)添加为Android M的build.grade的编译时依赖项?

android

如前所述这里,Android的M将不支持的Apache HTTP API。该文档指出:

请改用HttpURLConnection类。

要么

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

android {useLibrary’org.apache.http.legacy’}

我已经将项目对HttpClient的大部分用法转换为HttpURLConnection,但是,我仍然需要在一些领域中使用HttpClient。因此,我试图将“ org.apache.http.legacy”声明为编译时依赖项,但在build.gradle中遇到错误:

找不到Gradle DSL方法:“ useLibrary()”

我的问题是:如何在项目中将“ org.apache.http.legacy”声明为编译时依赖项?

任何帮助深表感谢。谢谢


阅读 592

收藏
2020-09-28

共1个答案

小编典典

对于API 23:

顶级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'
    ...
}

官方文档(不过仅供预览):http : //developer.android.com/about/versions/marshmallow/android-6.0-changes.html#behavior-apache-http-client

最新的Android Gradle插件变更日志:http ://tools.android.com/tech-docs/new-build-system

2020-09-28