Cannot resolve symbol HttpGet,HttpClient,HttpResponce in Android Studio

前端 未结 12 1940
深忆病人
深忆病人 2020-12-02 12:47

I just copy all the jar files of Http but Android Studio cann\'t import all these jar files.It gives an error : Cannot resolve symbol HttpGe

相关标签:
12条回答
  • 2020-12-02 13:21

    Google officially suggests to developers to use Volley library for networking related stuff Here, so Its time to switch to Volley, Happy coding

    0 讨论(0)
  • 2020-12-02 13:29

    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:

    In dependencies add:

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

    and also add this

    android {
        useLibrary 'org.apache.http.legacy'
    }
    
    0 讨论(0)
  • 2020-12-02 13:32

    Just add this in your dependencies

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

    Finally

    dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])    
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:23.0.1'
    compile 'com.android.support:design:23.0.1'
    compile 'org.apache.httpcomponents:httpcore:4.4.1'
    compile 'org.apache.httpcomponents:httpclient:4.5'
    }
    

    And also add this code:

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

    FYI

    Specify requirement for Apache HTTP Legacy library If your app is targeting API level 28 (Android 9.0) or above, you must include the following declaration within the element of AndroidManifest.xml.

     <uses-library
          android:name="org.apache.http.legacy"
          android:required="false" />
    
    0 讨论(0)
  • 2020-12-02 13:32

    You just rebuilt your project

    compile fileTree(dir: 'libs', include: ['*.jar'])
    
    0 讨论(0)
  • 2020-12-02 13:35

    For me, the below helped

    Find org.apache.http.legacy.jar which is in Android/Sdk/platforms/android-23/optional, add it to your dependency.

    Source

    0 讨论(0)
  • 2020-12-02 13:36

    please add these codes to your dependencies. It will work.

    implementation 'org.jbundle.util.osgi.wrapped:org.jbundle.util.osgi.wrapped.org.apache.http.client:4.1.2'
    
    dependencies {
        implementation fileTree(dir: 'libs', include: ['*.jar'])
        testCompile 'junit:junit:4.12'
        implementation 'com.android.support:appcompat-v7:23.1.0'
        implementation 'com.android.support:design:23.1.0'
        implementation 'com.android.support:cardview-v7:23.1.0'
        implementation 'com.android.support:recyclerview-v7:23.1.0'
    
        implementation 'org.jbundle.util.osgi.wrapped:org.jbundle.util.osgi.wrapped.org.apache.http.client:4.1.2'
    }
    
    0 讨论(0)
提交回复
热议问题