HttpClient won't import in Android Studio

后端 未结 23 2422
一生所求
一生所求 2020-11-22 14:44

I have a simple class written in Android Studio:

package com.mysite.myapp;

import org.apache.http.client.HttpClient;

public class Whatever {
    public voi         


        
相关标签:
23条回答
  • 2020-11-22 15:27

    Try this worked for me Add this dependency to your build.gradle File

    compile 'org.jbundle.util.osgi.wrapped:org.jbundle.util.osgi.wrapped.org.apache.http.client:4.1.2'
    
    0 讨论(0)
  • 2020-11-22 15:27

    in API 22 they become deprecated and in API 23 they removed them completely, a simple workaround if you don't need all the fancy stuff from the new additions is to simply use the .jar files from apache that were integrated before API 22, but as separated .jar files:

    1. http://hc.apache.org/downloads.cgi
    2. download httpclient 4.5.1, the zile file
    3. unzip all files
    4. drag in your project httpclient-4.5.1.jar, httpcore-4.4.3.jar and httpmime-4.5.1.jar
    5. project, right click, open module settings, app, dependencies, +, File dependency and add the 3 files
    6. now everything should compile properly
    
    0 讨论(0)
  • 2020-11-22 15:28

    ApacheHttp Client is removed in v23 sdk. You can use HttpURLConnection or third party Http Client like OkHttp.

    ref : https://developer.android.com/preview/behavior-changes.html#behavior-apache-http-client

    0 讨论(0)
  • 2020-11-22 15:29

    You have to add just one line

    useLibrary 'org.apache.http.legacy'
    

    into build.gradle(Module: app), for example

    apply plugin: 'com.android.application'
    
    android {
        compileSdkVersion 24
        buildToolsVersion "25.0.0"
    
        useLibrary 'org.apache.http.legacy'
    
        defaultConfig {
            applicationId "com.avenues.lib.testotpappnew"
            minSdkVersion 15
            targetSdkVersion 24
            versionCode 1
            versionName "1.0"
            testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        }
        buildTypes {
            release {
                minifyEnabled false
                proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            }
        }
    }
    
    dependencies {
        compile fileTree(dir: 'libs', include: ['*.jar'])
        androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
            exclude group: 'com.android.support', module: 'support-annotations'
        })
        compile 'com.android.support:appcompat-v7:24.2.1'
        testCompile 'junit:junit:4.12'
    }
    
    0 讨论(0)
  • 2020-11-22 15:29

    Error:(30, 0) Gradle DSL method not found: 'classpath()' Possible causes:

  • The project 'cid' may be using a version of the Android Gradle plug-in that does not contain the method (e.g. 'testCompile' was added in 1.1.0). Upgrade plugin to version 2.3.3 and sync project
  • The project 'cid' may be using a version of Gradle that does not contain the method. Open Gradle wrapper file
  • The build file may be missing a Gradle plugin. Apply Gradle plugin
0 讨论(0)
  • 2020-11-22 15:30

    TejaDroid's answer in below link helped me . Can't import org.apache.http.HttpResponse in Android Studio

    dependencies {
        compile fileTree(include: ['*.jar'], dir: 'libs')
        compile 'com.android.support:appcompat-v7:23.0.1'
    
        compile 'org.jbundle.util.osgi.wrapped:org.jbundle.util.osgi.wrapped.org.apache.http.client:4.1.2'
        ...
    }
    
    0 讨论(0)
  • 提交回复
    热议问题