【问题标题】:Adding HTTP Legacy to Android Studio将 HTTP Legacy 添加到 Android Studio
【发布时间】:2015-09-07 13:26:45
【问题描述】:

由于 Apache 的 HTTP 库已被 HttpURLConnection 弃用,因此我一直在尝试将遗留库添加到我的项目中。我加了一行

 useLibrary 'org.apache.http.legacy'

到 build.gradle 但仍然无法解析 HTTP 方法。我如何让它工作?

这些是我遇到的错误;

Error:(21, 59) error: cannot find symbol class List
Error:(21, 64) error: cannot find symbol class NameValuePair
Error:(23, 13) error: cannot find symbol class DefaultHttpClient
Error:(23, 48) error: cannot find symbol class DefaultHttpClient
Error:(24, 13) error: cannot find symbol class HttpEntity
Error:(25, 13) error: cannot find symbol class HttpResponse
Error:(28, 17) error: cannot find symbol class HttpPost
Error:(28, 41) error: cannot find symbol class HttpPost
Error:(30, 44) error: cannot find symbol class UrlEncodedFormEntity
Error:(37, 42) error: cannot find symbol variable URLEncodedUtils
Error:(40, 17) error: cannot find symbol class HttpGet
Error:(40, 39) error: cannot find symbol class HttpGet
Error:(48, 28) error: cannot find symbol variable EntityUtils`

以下是我的 build.gradle 文件:

buildscript {
    repositories {
        maven { url 'https://maven.fabric.io/public' }
    }

    dependencies {
        classpath 'io.fabric.tools:gradle:1.19.2'
    }
}
apply plugin: 'com.android.application'
apply plugin: 'io.fabric'

repositories {
    maven { url 'https://maven.fabric.io/public' }
}

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.1"
    useLibrary 'org.apache.http.legacy'

    defaultConfig {
        applicationId "com.radioafrica.music"
        minSdkVersion 11
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:cardview-v7:23.0.1'
    compile 'com.android.support:appcompat-v7:23.0.1'
    compile 'com.android.support:recyclerview-v7:23.0.1'
    compile 'com.android.support:palette-v7:23.0.1'
    compile 'com.android.support:design:23.0.1'
    compile 'com.android.support:support-v4:23.0.1'
    compile 'com.facebook.android:facebook-android-sdk:4.1.0'
    compile 'com.squareup.picasso:picasso:2.5.2'
    compile 'com.squareup.okhttp:okhttp:2.4.0'
    compile 'de.hdodenhof:circleimageview:1.3.0'
    compile 'com.github.ksoichiro:android-observablescrollview:1.5.0'
    compile('com.crashlytics.sdk.android:crashlytics:2.5.0@aar') {
        transitive = true;
    }
    compile('com.twitter.sdk.android:twitter:1.6.1@aar') {
        transitive = true;
    }
    compile 'com.nineoldandroids:library:2.4.0'

}

【问题讨论】:

  • 请将您的 build.gradle 添加到您的帖子中

标签: android apache httpclient httpurlconnection


【解决方案1】:

经过一番研究,我发现该库实际上是在编译和打包时包含的,但在 IDE 中没有显示。

作为一种解决方法,您可以删除该行

useLibrary 'org.apache.http.legacy'

将文件 org.apache.http.legacy.jar 从Android/Sdk/platforms/android-23/optional 复制到项目中的libs 文件夹。

报告此问题的人的参考

https://code.google.com/p/android/issues/detail?id=181474

https://code.google.com/p/android/issues/detail?id=183668

【讨论】:

  • 我已经更新到 v1.3.1 但问题仍然存在
  • 是的,事实上有好几次。
  • Android Studio 新手,复制文件后记得选择“添加为库...”
猜你喜欢
  • 2018-11-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多