简述使用configurations.all统一androidx的版本
编者:李国帅qq:9611153 微信lgs9611153时间:2021-5-29问题描述:因为程序中使用了越多越多的基于androidx的插件,继续使用android.support包名出现了许多不便。为了方便后续加入其他的插件,就把android的支持包进行了更改。替换的步骤按网友的做法就可以了,这里就简单介绍下自己在替换过程中碰到了几个小问题。1、如果使用androidx包名必须在所有模块都
问题描述:
因为程序中使用了越多越多的基于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文件中
更多推荐
所有评论(0)