如何将 Apache HTTP API(旧版)作为编译时依赖项添加到 build.grade for Android M? [英] How to add Apache HTTP API (legacy) as compile-time dependency to build.grade for Android M?

查看:23
本文介绍了如何将 Apache HTTP API(旧版)作为编译时依赖项添加到 build.grade for Android M?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此处所述,Android M将不支持 Apache HTTP API.文档说明:

As mentioned here, Android M will not support the Apache HTTP API. The docs state to:

改用 HttpURLConnection 类.

use the HttpURLConnection class instead.

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

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

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

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

I have converted much of my project's usage of HttpClient to HttpURLConnection, however, I still need to use the HttpClient in a few areas. Hence, I am trying to declare 'org.apache.http.legacy' as a compile-time dependency but am getting an error in build.gradle:

找不到 Gradle DSL 方法:'useLibrary()'

Gradle DSL method not found: 'useLibrary()'

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

My question is: how do I declare 'org.apache.http.legacy' as a compile-time dependency in my project?

非常感谢任何帮助.谢谢

Any help is much appreciated. Thanks

推荐答案

对于 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

Official docs (for preview though): 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-构建系统

Latest android gradle plugin changelog: http://tools.android.com/tech-docs/new-build-system

这篇关于如何将 Apache HTTP API(旧版)作为编译时依赖项添加到 build.grade for Android M?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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