【问题标题】:httpclient conflict with classes now provided by Androidhttpclient 与 Android 现在提供的类冲突
【发布时间】:2019-07-03 12:18:57
【问题描述】:

在 Android Studio 3.4.1 中

app/build.gradle:


dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])

    implementation 'com.android.support:appcompat-v7:28.0.0'
    implementation 'org.apache.httpcomponents:httpclient:4.5.9'

    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}

但我在这一行出现错误;

implementation 'org.apache.httpcomponents:httpclient:4.5.9'

错误:

httpclient defines classes that conflict with classes now provided by Android. Solutions include finding newer versions or alternative libraries that don't have the same problem (for example, for httpclient use HttpUrlConnection or okhttp instead), or repackaging the library using something like jarjar. more... (Ctrl+F1)

【问题讨论】:

  • 从 build.gradle 中删除这一行时会发生什么?您正在使用这个库的哪些类?
  • @oemel09 然后我得到编译错误:import org.apache.http.HttpHost; - 无法解析符号 HttpHost

标签: android-gradle-plugin apache-httpclient-4.x


【解决方案1】:

查看此更新日志以获取 Android API
您应该将 Apache HTTP 函数替换为 HttpURLConnection 或使用您的 build.gradle 中的此片段来继续使用现已弃用的 Apache 库。

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

【讨论】:

    猜你喜欢
    • 2019-06-18
    • 1970-01-01
    • 2021-12-08
    • 1970-01-01
    • 2018-04-09
    • 1970-01-01
    • 2015-05-10
    • 1970-01-01
    • 2018-10-22
    相关资源
    最近更新 更多