HttpClient won't import in Android Studio

后端 未结 23 2421
一生所求
一生所求 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:15

    For android API 28 and higher in Manifest.xml inside application tag

        <application
        .
        .
        .
    
        <uses-library android:name="org.apache.http.legacy" android:required="false"/>
    
    0 讨论(0)
  • 2020-11-22 15:16

    HttpClient is not supported in sdk 23 and 23+.

    If you need to use into sdk 23, add below code to your gradle:

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

    Its working for me. Hope useful for you.

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

    I think depending on which Android Studio version you have, it's important you update your android studio as well, i was becoming frustrated too following everyone's advice but no luck, until i had to upgrade my android version from 1.3 to 1.5, the errors disappeared like magic.

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

    If you want import some class like :

    import org.apache.http.NameValuePair;
    import org.apache.http.client.HttpClient; 
    import org.apache.http.client.entity.UrlEncodedFormEntity;
    import org.apache.http.client.methods.HttpPost;
    import org.apache.http.impl.client.DefaultHttpClient;
    import org.apache.http.message.BasicNameValuePair;
    import org.apache.http.params.BasicHttpParams;
    import org.apache.http.params.HttpConnectionParams;
    import org.apache.http.params.HttpParams;
    

    You can add the following line in the build.gradle (Gradle dependencies)

    dependencies {
        implementation fileTree(dir: 'libs', include: ['*.jar'])
        implementation 'com.android.support:appcompat-v7:27.1.0'
        implementation 'com.android.support:support-v4:27.1.0'
    
        .
        .
        .
    
        implementation 'org.jbundle.util.osgi.wrapped:org.jbundle.util.osgi.wrapped.org.apache.http.client:4.1.2'
    
    }
    
    0 讨论(0)
  • 2020-11-22 15:25

    Another way is if you have httpclient.jar file then you can do this :

    Paste your .jar file in "libs folder" in your project. Then in gradle add this line in your build.gradle(Module:app)

    dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    compile 'com.android.support:appcompat-v7:23.0.0'
    compile files('libs/httpcore-4.3.3.jar')
    }
    
    0 讨论(0)
  • 2020-11-22 15:27

    HttpClient is not supported any more in sdk 23. You have to use URLConnection or downgrade to sdk 22 (compile 'com.android.support:appcompat-v7:22.2.0')

    If you need sdk 23, add this to your gradle:

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

    You also may try to download and include HttpClient jar directly into your project or use OkHttp instead

    0 讨论(0)
提交回复
热议问题