简述使用configurations.all统一androidx的版本

编者:李国帅

qq:9611153 微信lgs9611153

时间:2021-5-29 

问题描述:

因为程序中使用了越多越多的基于androidx的插件,继续使用android.support包名出现了许多不便。为了方便后续加入其他的插件,就把android的支持包进行了更改。

替换的步骤按网友的做法就可以了,这里就简单介绍下自己在替换过程中碰到了几个小问题。

1、如果使用androidx包名必须在所有模块都使用相同版本的androdx,不能一部分析使用android.support,一部分使用androidx。

2、需要把所有的android.support都按照“旧版本包与AndroidX对照表”进行替换。

3、不同插件使用的androidx版本如果不一致会出问题,需要使用configurations.all进行统一,那configurations.all语句放在什么地方?

 

我也发现,很多人说使用configurations.all可以解决支持库版本不一致的问题,但到底放在什么地方还真没人讲,那我就补个缺。

 

概念:android studio,androidx,android.support,configurations

 

androidx 是对 android.support.xxx 包的整理后产物。由于之前的support包过于混乱,所以,google推出了 androidX。

1、全部使用androidx,不然可能会出现类似下面的错误:

Android resource linking failed

AAPT: error: resource style/Widget.AppCompat.TextView (aka com.xxx.xxx:style/Widget.AppCompat.TextView) not found.

error: resource style/Widget.AppCompat.TextView (aka com.xxx.xxx:style/Widget.AppCompat.TextView) not found.

error: resource style/Widget.AppCompat.TextView (aka com.xxx.xxx:style/Widget.AppCompat.TextView) not found.

error: resource style/Widget.AppCompat.TextView (aka com.xxx.xxx:style/Widget.AppCompat.TextView) not found.

error: resource style/Widget.AppCompat.TextView (aka com.xxx.xxx:style/Widget.AppCompat.TextView) not found.

error: resource style/Widget.AppCompat.TextView (aka com.xxx.xxx:style/Widget.AppCompat.TextView) not found.

error: failed linking references.

 

 

2、按照“旧版本包与AndroidX对照表”进行替换依赖库比如

    implementation 'com.android.support:appcompat-v7:28.0.0'

    implementation 'com.android.support:support-v4:28.0.0'

    implementation "com.android.support:support-annotations:28.0.0"

    implementation "com.android.support:recyclerview-v7:28.0.0"

 

替换为

   implementation 'androidx.appcompat:appcompat:1.2.0'

   implementation 'androidx.recyclerview:recyclerview:1.2.0'

 

3、使用同一的androidx版本

不光是子模块中需要使用同一版本,而且依赖的第三方包也要使用同一版本的androidx,不然会出现下面错误

 

Execution failed for task ':xxxmodule:dataBindingMergeDependencyArtifactsDebug'.

> Could not resolve all files for configuration ':xxxmodule:debugCompileClasspath'.

   > Could not resolve androidx.appcompat:appcompat:1.2.0.

     Required by:

         project :xxxmodule

         project :xxxmodule > androidx.constraintlayout:constraintlayout:2.0.4

      > Cannot find a version of 'androidx.appcompat:appcompat' that satisfies the version constraints:

           Dependency path 'myapp:xxxmodule:unspecified' --> 'androidx.appcompat:appcompat:1.2.0'

           Constraint path 'myapp:xxxmodule:unspecified' --> 'androidx.appcompat:appcompat:{strictly 1.0.0}' because of the following reason: debugRuntimeClasspath uses version 1.0.0

           Dependency path 'myapp:xxxmodule:unspecified' --> 'androidx.constraintlayout:constraintlayout:2.0.4' --> 'androidx.appcompat:appcompat:1.2.0'

           Dependency path 'myapp:xxxmodule:unspecified' --> 'com.google.android.material:material:1.2.1' --> 'androidx.appcompat:appcompat:1.1.0'

           Dependency path 'myapp:xxxmodule:unspecified' --> 'com.github.duanhong169:colorpicker:1.1.6' --> 'androidx.appcompat:appcompat:1.0.0'

           Dependency path 'myapp:xxxmodule:unspecified' --> 'myapp:commonframework:unspecified' --> 'com.trello.rxlifecycle2:rxlifecycle-components:2.2.0' --> 'androidx.appcompat:appcompat:1.0.0'

           Dependency path 'myapp:xxxmodule:unspecified' --> 'myapp:commonframework:unspecified' --> 'com.github.hackware1993:MagicIndicator:1.5.0' --> 'androidx.appcompat:appcompat:1.0.0'

           Dependency path 'myapp:xxxmodule:unspecified' --> 'com.github.duanhong169:colorpicker:1.1.6' --> 'com.github.duanhong169:checkerboarddrawable:1.0.2' --> 'androidx.appcompat:appcompat:1.0.0'

 

如何解决呢?

可使用configurations.all解决androidx版本冲突问题,大家都知道使用configurations.all,可是放在什么地方呢?

其实也就是放在应用根目录下面的build.gradle文件中

  • 5
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

微澜-

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值