Android   发布时间:2022-04-28  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了android – 无法解析符号:’HttpClient’,即使在添加依赖项之后大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我试添加Apache公共库的各种依赖项.

我试httpClient,httpCore和许多不同的版本.也可以从外部罐子和maven建议.

我最终得到了这个:

compile 'org.apache.httpcomponents:httpcore:4.4.1'
compile 'org.apache.httpcomponents:httpclient:4.3.5'

它仍然给我无法解析httpClient并且无法解析httpPost等.

它不提供我导入类.

http帖子的代码

// Create a new httpClient and Post Header
            httpClient httpclient = new DefaulthttpClient();
            httpPost httppost = new httpPost("http://fdsgsfdgs);

            try {
                // Add your data
                List<NameValuePair> nameValuePairs = new ArrayList<>(2);
                nameValuePairs.add(new BasicNameValuePair("id",null));
                nameValuePairs.add(new BasicNameValuePair("name","TestFromAppSpell"));
                nameValuePairs.add(new BasicNameValuePair("damage","12345"));
                nameValuePairs.add(new BasicNameValuePair("heal","50"));
                nameValuePairs.add(new BasicNameValuePair("description","Testtestest"));
                nameValuePairs.add(new BasicNameValuePair("coordinates",coordinates));
                httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));

                // Execute http Post request
                httpResponse response = httpclient.execute(httppost);
                Sy@L_489_2@.out.println("http post done!");
            } catch (ClientProtocolException E) {
                // TODO Auto-generated catch block
            } catch (IOException E) {
                // TODO Auto-generated catch block
            }

Gradle文件

buildscript {
    repositories {
        jcenter()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:1.2.3'
    }
}

apply plugin: 'com.android.application'

repositories {
    jcenter()
}

dependencies {
    compile 'com.android.support:support-v4:23.0.0'
    compile 'com.android.support:gridlayout-v7:23.0.0'
    compile 'com.android.support:cardview-v7:23.0.0'
    compile 'org.apache.httpcomponents:httpcore:4.4.1'
    compile 'org.apache.httpcomponents:httpclient:4.3.5'
}

dependencies {
    compile 'com.android.support:appcompat-v7:+'
    compile fileTree(dir: 'libs',include: ['*.jar'])
}

// The sample build uses multiple directories to
// keep boilerplate and common code separate from
// the main sample code.
List<String> dirs = [
    'main',// main sample code; look here for thE interesTing stuff.
    'common',// components that are reused by multiple samples
    'template'] // boilerplate code that is generated by the sample template process

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.0"

    defaultConfig {
        minSdkVersion 11
        targetSdkVersion 23
    }

    compiLeoptions {
        sourceCompatibility JavaVersion.VERSION_1_7
        targetCompatibility JavaVersion.VERSION_1_7
    }

    sourceSets {
        main {
            dirs.each { dir ->
                java.srcDirs "src/${dir}/java"
                res.srcDirs "src/${dir}/res"
            }
        }
        androidTest.setRoot('tests')
        androidTest.java.srcDirs = ['tests/src']

    }

}

解决方法

SDK 23中不再支持httpClient.您必须使用URLConnection或降级到SDK 22(编译’com.android.support:appcompat-v7:22.2.0′)

如果您需要SDK 23,请将其添加到您的gradle:

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

大佬总结

以上是大佬教程为你收集整理的android – 无法解析符号:’HttpClient’,即使在添加依赖项之后全部内容,希望文章能够帮你解决android – 无法解析符号:’HttpClient’,即使在添加依赖项之后所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。