Lint错误:`httpclient`定义了与Android现在提供的类冲突的类 [英] Lint error: `httpclient` defines classes that conflict with classes now provided by Android
问题描述
我正在尝试通过遵循当尝试构建签名的发行版APK时,出现以下问题:
When trying to build the signed release APK, I get this lint problem:
httpclient定义了与Android现在提供的类冲突的类.解决方案包括查找没有相同问题的较新版本或替代库(例如,对于httpclient使用HttpUrlConnection或okhttp替代),或使用jarjar之类的库重新打包该库.
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.
这是我的gradle依赖项:
Here are my gradle dependencies:
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.google.android.gms:play-services-auth:16.0.1'
implementation 'com.android.support:design:27.1.1'
implementation 'com.android.support:customtabs:27.1.1'
implementation 'com.google.http-client:google-http-client-gson:1.26.0'
implementation('com.google.api-client:google-api-client-android:1.26.0') {
exclude group: 'org.apache.httpcomponents'
}
implementation('com.google.apis:google-api-services-drive:v3-rev136-1.25.0') {
exclude group: 'org.apache.httpcomponents'
}
}
我猜这是由以下原因引起的:
I'm guessing the problem is caused by:
implementation 'com.google.http-client:google-http-client-gson:1.26.0'
我已经尝试过发布的解决方案 和此处,但是它们不起作用.
I've tried the solutions posted here and here, but they don't work.
类似于此评论说:
如果排除httpclient,我将无法获得发布APK
I am not able to get release apk if exclude httpclient
还有什么其他解决方案?
What other solution(s) are there?
推荐答案
尝试将org.apache.httpcomponents
模块也从google-http-client-gson
中排除.
然后,如果您的项目需要Apache HttpClient类,请使用一些包装器来提供它们,例如此即使在定位最新的SDK时也能很好地工作.
Try excluding the org.apache.httpcomponents
module also from google-http-client-gson
.
Then, if your projects requires Apache HttpClient classes, use some wrapper to provide them, e.g. this one works great even when targetting the newest SDK.
我在app\build.gradle
中使用以下代码块,并且工作正常(我只是使用google-http-client-gson
模块的旧版本):
I use the following block in app\build.gradle
and it works fine (I just use older version of google-http-client-gson
module):
compile ('com.google.http-client:google-http-client-gson:1.19.0') {
//Exclude conflicting modules
exclude module: 'httpclient'
exclude module: 'commons-logging'
}
//Add HttpClient classes from a different package
compile 'cz.msebera.android:httpclient:4.5.8'
然后,您只需将所有org.apache.http
导入内容更改为cz.msebera.android.httpclient
,例如
Then you will just have to change all your org.apache.http
imports to cz.msebera.android.httpclient
, e.g.
import org.apache.http.HttpResponse
成为
import cz.msebera.android.httpclient.HttpResponse
这篇关于Lint错误:`httpclient`定义了与Android现在提供的类冲突的类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!