apache http导入无效

时间:2015-12-11 19:50:27

标签: android apache import

我正在使用useLibrary' org.apache.http.legacy'在我的build.gradle中,但有些导入无法正常工作

以下是我的导入:

import org.apache.http.HttpEntity; // Working
import org.apache.http.HttpResponse; // Working
import org.apache.http.client.ClientProtocolException; // Not Working
import org.apache.http.client.methods.HttpPost; // Not Working
import org.apache.http.impl.client.DefaultHttpClient; // Not Working
import org.apache.http.params.BasicHttpParams; // Working

这是我的build.gradle

apply plugin: 'com.android.application'

android {
  compileSdkVersion 23
  buildToolsVersion "23.0.2"

  useLibrary 'org.apache.http.legacy'

defaultConfig {
    applicationId "com.user.app"
    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:23.1.0'
  compile 'org.apache.httpcomponents:httpcore:4.4.3'
}

1 个答案:

答案 0 :(得分:0)

尝试将org.apache.http.legacy.jar添加到libs文件夹中。

您可以在Android/Sdk/platforms/android-23/optional

中找到此jar

将此行添加到app.gradle文件

compile fileTree(dir: 'libs', include: ['*.jar'])

并删除useLibrary 'org.apache.http.legacy'

这样我使用库没有任何问题