android中gradle 3.1.4 处理com.android.support libraries版本不一致冲突问题

本文介绍了解决因第三方库依赖相同库但版本不同的问题。通过示例展示了如何使用exclude命令排除特定模块来统一版本。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

在添加依赖的时候,由于可能使用的第三方库依赖了相同的库,但是版本不同,会报错提示版本不一致

比如这里我添加了permissionsDispatcher的依赖,导致com.android.support报错提示如下

All com.android.support libraries must use the exact same version specification (mixing versions can lead to runtime crashes). Found versions 27.1.1, 27.0.2. Examples include com.android.support:animated-vector-drawable:27.1.1 and com.android.support:support-media-compat:27.0.2 
There are some combinations of libraries, or tools and libraries, that are incompatible, or can lead to bugs. One such incompatibility is compiling with a version of the Android support libraries that is not the latest version (or in particular, a version lower than your targetSdkVersion).

可以看到是因为项目com.android.support库版本为27.1.1,第三方库里面是27.0.2,所以用以下方式将冲突的包剔除,统一使用项目的版本

implementation ("com.github.hotchemi:permissionsdispatcher:3.3.1"){
    exclude group: 'com.android.support',module:'support-media-compat'
    exclude group: 'com.android.support',module:'support-v13'
}

这里使用 exclude 剔除 'com.android.support'库里的冲突模块 'support-media-compat' 和 'support-v13',再build一次就不再报错冲突了。

注意:这种方式剔除模块原本依赖的库,可能会出现因为版本不同而产生的问题,要确保可以使用同一版本的依赖

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值