httpclient 与现在由 Android 提供的 类 冲突
httpclient conflict with classes now provided by Android
在 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)
查看 Android API 的更新日志。
您应该用 HttpURLConnection 替换 Apache HTTP 函数,或者使用 build.gradle
中的这个片段来继续使用现已弃用的 Apache 库。
android {
useLibrary 'org.apache.http.legacy'
}
在 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)
查看 Android API 的更新日志。
您应该用 HttpURLConnection 替换 Apache HTTP 函数,或者使用 build.gradle
中的这个片段来继续使用现已弃用的 Apache 库。
android {
useLibrary 'org.apache.http.legacy'
}