HttpClient won't import in Android Studio

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

    Android 6.0 (API Level 23) release removes support for the Apache HTTP client. Hence you can not use this library directly in API 23. But there is a way to use it. Add useLibrary ‘org.apache.http.legacy’ in your build.gradle file as below-

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

    If this does not work you may apply the following hack-

    – Copy org.apache.http.legacy.jar which is in /platforms/android-23/optional path of your Android SDK directory to your project’s app/libs folder.

    – Now Add compile files(‘libs/org.apache.http.legacy.jar’) inside dependencies{} section of build.gradle file.

提交回复
热议问题