Android Gradle Apache HttpClient 不存在?

标签 android android-studio intellij-idea gradle android-gradle-plugin

我正在尝试将 IntelliJ 项目转换为 Android Studio 的 Gradle 系统,但我遇到了 Apache HttpClient 错误?我错过了什么吗,我得到的错误如下:

Error:(10, 30) error: package org.apache.http.client does not exist
Error:(11, 30) error: package org.apache.http.client does not exist
Error:(12, 37) error: package org.apache.http.client.entity does not exist
Error:(13, 38) error: package org.apache.http.client.methods does not exist
Error:(14, 38) error: package org.apache.http.client.methods does not exist
Error:(15, 38) error: package org.apache.http.client.methods does not exist
Error:(16, 35) error: package org.apache.http.impl.client does not exist
Error:(134, 33) error: cannot find symbol class HttpUriRequest
Error:(164, 39) error: cannot find symbol class HttpUriRequest
Error:(106, 17) error: cannot find symbol class HttpGet
Error:(106, 39) error: cannot find symbol class HttpGet
Error:(117, 17) error: cannot find symbol class HttpPost
Error:(117, 40) error: cannot find symbol class HttpPost
Error:(125, 43) error: cannot find symbol class UrlEncodedFormEntity
Error:(135, 9) error: cannot find symbol class HttpClient
Error:(135, 33) error: cannot find symbol class DefaultHttpClient
Error:(155, 18) error: cannot find symbol class ClientProtocolException
Error:(165, 9) error: cannot find symbol class HttpClient
Error:(165, 33) error: cannot find symbol class DefaultHttpClient
Error:(185, 18) error: cannot find symbol class ClientProtocolException

我的 build.gradle 文件有以下依赖:

dependencies {
    compile 'com.google.android.gms:play-services:+'
    compile 'org.apache.httpcomponents:httpclient:4.2.6'
    compile 'org.apache.httpcomponents:httpmime:4.2.6'
    compile files('libs/core.jar')
}

似乎很多人都遇到了类似的问题,但 SO 或 Google 都没有解决方案,所以我希望这个问题能对 future 的搜索者有所帮助。

最佳答案

如果您使用 target sdk as 23 在您的 build.gradle 中添加以下代码

android{
    compileSdkVersion 23
    buildToolsVersion '23.0.1'
    useLibrary  'org.apache.http.legacy'
}

并将您的构建脚本更改为

classpath 'com.android.tools.build:gradle:1.3.0' 

更多信息请关注 link

关于Android Gradle Apache HttpClient 不存在?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31433687/

相关文章:

android-studio - 为什么即使我已经在其中明确使用了变量,android studio也会对未使用的变量给出警告

git - IDEA IntelliJ git 克隆

android - openssl s_client -connect 默认为子域?

php - 将 QR Code Scanner android 应用程序连接到在线 mySQL 数据库

安卓慢速软键盘打开

android - Gallery/AdapterView 子绘图状态

android - 图像未从 android 插入到 MySQL

java - 如何在android studio中使用正弦、余弦、对数函数

java - 如何修复 intellij 中损坏的 java 类?

java - 如何将现有的 Ant build.xml 导入 IntelliJ IDEA