解决依赖库版本不一致导致的问题

在使用第三方库和Google官方库时,遇到版本冲突导致的编译错误,如DexArchiveMergerException和不同版本appcompat库的问题。解决办法是在build.gradle的dependencies中精确指定所需库的版本。
摘要由CSDN通过智能技术生成

我们在写代码时候总会借鉴一些第三方库,有的是别人写的比较优秀的,有的则是google官方提供的,但是我们在依赖之后编译运行时候总会出各种各样的问题:

1、Error:Execution failed for task ':app:transformDexArchiveWithExternalLibsDexMergerForDebug'.

> java.lang.RuntimeException: java.lang.RuntimeException: com.android.builder.dexing.DexArchiveMergerException: Unable to merge dex  

2、“Error:Execution failed for task ':app:preDebugBuild'.

> Android dependency 'com.android.support:appcompat-v7' has different version for the compile (27.0.2) and runtime (27.1.0) classpath. You should manually set the same version via DependencyResolution”,

针对上面的support:appcompat库我们可以像下面一样子来指定自己所依赖的版本:

在build.gradle的dependencies中添加如下代码即可

configurations.all {
        resolutionStrategy.force 'com.android.support:support-annotations:26.1.0'
        //循环一个个的依赖库
        resolutionStrategy.eachDependency {
  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值