相关疑难解决方法(0)

HttpClient不会在Android Studio中导入

我有一个用Android Studio编写的简单类:

package com.mysite.myapp;

import org.apache.http.client.HttpClient;

public class Whatever {
    public void headBangingAgainstTheWallExample () {
        HttpClient client = new DefaultHttpClient();
    }
}
Run Code Online (Sandbox Code Playgroud)

从这里我得到以下编译时错误:

Cannot resolve symbol HttpClient

HttpClient包含在Android Studio SDK中?即使不是,我也将它添加到我的Gradle构建中:

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:23.0.0'
    compile 'org.apache.httpcomponents:httpclient:4.5'
}
Run Code Online (Sandbox Code Playgroud)

无论有没有最后一个编译行,错误都是一样的.我错过了什么?

android gradle apache-httpclient-4.x android-gradle-plugin

345
推荐指数
14
解决办法
54万
查看次数

Gradle无法与"无法找到可选库"同步

我不得不重新安装我的系统,今天当我尝试与gradle同步时,我在Android Studio中收到此错误:

Warning: Unable to find optional library: org.apache.http.legacy
Run Code Online (Sandbox Code Playgroud)

我的项目是:

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:1.3.0'
    }
}

allprojects {
    repositories {
        mavenCentral()
    }
}
Run Code Online (Sandbox Code Playgroud)

我的模块是gradle:

apply plugin: 'android'

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

    compileSdkVersion 23
    buildToolsVersion '23.0.2'
    defaultConfig {
        minSdkVersion 16
        targetSdkVersion 23
    }
    buildTypes {
        release {
        }
    }
    productFlavors {
    }
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    compile 'com.android.support:support-v4:23.1.1'
    compile 'com.android.support:appcompat-v7:23.1.1'
}
Run Code Online (Sandbox Code Playgroud)

来自谷歌文档:

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

android {
    useLibrary 'org.apache.http.legacy'
} …
Run Code Online (Sandbox Code Playgroud)

android gradle android-studio build.gradle

17
推荐指数
3
解决办法
4万
查看次数

Android studio无法解析符号'HttpClient'

我有一个Android项目,我需要使用http调用.

我使用这个简单的代码:

public void onGetClick(View v) {
    HttpClient client = new DefaultHttpClient();
    HttpGet request = new HttpGet("http://www.google.com");
    HttpResponse response = client.execute(request);

    BufferedReader rd = new BufferedReader(new InputStreamReader
(response.getEntity().getContent()));

    String line = "";
    while ((line = rd.readLine()) != null) {
        Log.d("WM.ALS", line);
    }

}
Run Code Online (Sandbox Code Playgroud)

但我找不到HttpClient库.

我将从Apache下载的.jar文件(http://hc.apache.org/downloads.cgi)添加到dir/lib中,并添加到"build.gradle(Module:app)"文件中,我补充说:

dependencies {
  compile fileTree(dir: 'libs', include: ['*.jar'])
  testCompile 'junit:junit:4.12'
  compile 'com.android.support:appcompat-v7:23.1.1'

  compile 'com.android.support:design:23.0.1'
  compile 'org.apache.httpcomponents:httpcore-4.4.3'
  compile 'org.apache.httpcomponents:httpclient-4.5.1'
Run Code Online (Sandbox Code Playgroud)

}

但仍然无法工作..

我该怎么办?

java android android-studio

3
推荐指数
1
解决办法
6743
查看次数