Apache HttpClient Android (Gradle)

前端 未结 8 2112
不知归路
不知归路 2020-12-04 12:11

I have added this line to my build.gradle

compile group: \'org.apache.httpcomponents\' , name: \'httpclient-android\' , version: \'4.3.5\'

相关标签:
8条回答
  • 2020-12-04 12:26

    None of the others worked for me. I had to add the following dependency, as explained here

    compile group: 'cz.msebera.android' , name: 'httpclient', version: '4.4.1.1'
    

    because I was targeting API 23.

    0 讨论(0)
  • 2020-12-04 12:31

    if you are using target sdk as 23 add below code in your build.gradle

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

    additional note here: dont try using the gradle versions of those files. they are broken (28.08.15). I tried over 5 hours to get it to work. it just doesnt. not working:

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

    another thing dont use:

    'org.apache.httpcomponents:httpclient-android:4.3.5.1'
    

    its referring 21 api level.

    0 讨论(0)
  • 2020-12-04 12:37

    Try adding this to your dependencies:

    compile 'org.apache.httpcomponents:httpclient:4.4-alpha1'
    

    And generally if you want to use a library and you are searching for the Gradle dependency line you can use Gradle Please

    EDIT: Check this one too.

    0 讨论(0)
  • 2020-12-04 12:37

    Working gradle dependency

    Try this:

    compile 'org.jbundle.util.osgi.wrapped:org.jbundle.util.osgi.wrapped.org.apache.http.client:4.1.2'

    0 讨论(0)
  • 2020-12-04 12:38

    I don't know why but (for now) httpclient can be compiled only as a jar into the libs directory in your project. HttpCore works fine when it is included from mvn like that:

    dependencies {
          compile 'org.apache.httpcomponents:httpcore:4.4.3'
    }
    
    0 讨论(0)
  • 2020-12-04 12:40

    I searched over and over this solution works like a charm ::

        apply plugin: 'com.android.application'
        android {
            compileSdkVersion 25
            buildToolsVersion "25.0.3"
            defaultConfig {
                applicationId "com.anzma.memories"
                useLibrary 'org.apache.http.legacy'
                minSdkVersion 15
                targetSdkVersion 25
                versionCode 1
                versionName "1.0"
                testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
            }
     packagingOptions {
                exclude 'META-INF/DEPENDENCIES.txt'
                exclude 'META-INF/LICENSE.txt'
                exclude 'META-INF/NOTICE.txt'
                exclude 'META-INF/NOTICE'
                exclude 'META-INF/LICENSE'
                exclude 'META-INF/DEPENDENCIES'
                exclude 'META-INF/notice.txt'
                exclude 'META-INF/license.txt'
                exclude 'META-INF/dependencies.txt'
                exclude 'META-INF/LGPL2.1'
            }
        buildTypes {
                release {
                    minifyEnabled false
                    proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
                }
            }
        }
        dependencies {
            compile fileTree(dir: 'libs', include: ['*.jar'])
            compile('org.apache.httpcomponents:httpmime:4.3.6') {
                exclude module: 'httpclient'
            }
            compile 'org.apache.httpcomponents:httpclient-android:4.3.5'
            compile 'com.android.support:appcompat-v7:25.3.1'
            testCompile 'junit:junit:4.12'
        }
    
    0 讨论(0)
提交回复
热议问题