Jetpack Compose学习(10)——使用Compose物料清单BOM,更好管理依赖版本
原文地址:Jetpack Compose学习(10)——使用Compose物料清单BOM,更好管理依赖版本 - Stars-One的杂货小窝
本期讲解下关于Android推出的BOM来简化我们添加compose依赖过于繁杂的问题
本系列以往文章请查看此分类链接Jetpack compose学习
介绍
BOM为
Bill of Material
的缩写原本是制造业中的一个概念,比如组装一个手机,BoM包括屏幕、手机壳、芯片、主板、电池等,按照既定的物料清单采购好配件,工厂进行组装生产
对于我们开发者来说, 有什么作用的?
举个例子,像compose的一系列依赖,版本众多,更新且又频繁,且又相互有所依赖,对于我们开发来说,理清这些层层次次关系足以头大,然后还有个致命问题,我们几个库使用不同版本,可能还会导致编译直接报错,出现依赖版本等冲突问题
鉴于上述原因,Android官方就是提供了一个BOM的概念,也就是今天的正文。
BoM 是否会自动将所有 Compose 库添加到我的应用中?
不会。要在您的应用中实际添加和使用 Compose 库,您必须在模块(应用级)Gradle 文件(通常是 app/build.gradle)中将每个库声明为单独的依赖项行。
使用 BoM 可确保应用中的任何 Compose 库版本兼容,但 BoM 实际上并不会将这些 Compose 库添加到您的应用中。
为什么建议使用 BoM 管理 Compose 库版本?
今后,Compose 库将单独进行版本控制,这意味着版本号将开始按照自己的节奏递增。每个库的最新稳定版本已经过测试,并保证能够很好地协同工作。不过,找到每个库的最新稳定版本可能比较困难,而 BoM 会帮助您自动使用这些最新版本
使用
使用的话也很简单,如下面例子:
dependencies {
def composeBom = platform('androidx.compose:compose-bom:2022.12.00')
implementation composeBom
androidTestImplementation composeBom
implementation 'androidx.compose.ui:ui'
implementation 'androidx.activity:activity-compose'
// Material Design 3
implementation 'androidx.compose.material3:material3'
}
需要注意的是,我们引入之后,后续的compose相关的库,都不需要写版本号了,由BOM默认指定版本
当然,如果你想指定版本,也是可以的,会优先以你指定的版本为准
库组 | 版本 (2022.10.00) | 版本 (2022.11.00) | 版本 (2022.12.00) | 版本 (2023.01.00) |
---|---|---|---|---|
androidx.compose.animation:animation | 1.3.0 | 1.3.1 | 1.3.2 | 1.3.3 |
androidx.compose.animation:animation-core | 1.3.0 | 1.3.1 | 1.3.2 | 1.3.3 |
androidx.compose.animation:animation-graphics | 1.3.0 | 1.3.1 | 1.3.2 | 1.3.3 |
androidx.compose.foundation:foundation | 1.3.0 | 1.3.1 | 1.3.1 | 1.3.1 |
androidx.compose.foundation:foundation-layout | 1.3.0 | 1.3.1 | 1.3.1 | 1.3.1 |
androidx.compose.material:material | 1.3.0 | 1.3.1 | 1.3.1 | 1.3.1 |
androidx.compose.material:material-icons-core | 1.3.0 | 1.3.1 | 1.3.1 | 1.3.1 |
androidx.compose.material:material-icons-extended | 1.3.0 | 1.3.1 | 1.3.1 | 1.3.1 |
androidx.compose.material:material-ripple | 1.3.0 | 1.3.1 | 1.3.1 | 1.3.1 |
androidx.compose.material3:material3 | 1.0.0 | 1.0.1 | 1.0.1 | 1.0.1 |
androidx.compose.material3:material3-window-size-class | 1.0.0 | 1.0.1 | 1.0.1 | 1.0.1 |
androidx.compose.runtime:runtime | 1.3.0 | 1.3.1 | 1.3.2 | 1.3.3 |
androidx.compose.runtime:runtime-livedata | 1.3.0 | 1.3.1 | 1.3.2 | 1.3.3 |
androidx.compose.runtime:runtime-rxjava2 | 1.3.0 | 1.3.1 | 1.3.2 | 1.3.3 |
androidx.compose.runtime:runtime-rxjava3 | 1.3.0 | 1.3.1 | 1.3.2 | 1.3.3 |
androidx.compose.runtime:runtime-saveable | 1.3.0 | 1.3.1 | 1.3.2 | 1.3.3 |
androidx.compose.ui:ui | 1.3.0 | 1.3.1 | 1.3.2 | 1.3.3 |
androidx.compose.ui:ui-geometry | 1.3.0 | 1.3.1 | 1.3.2 | 1.3.3 |
androidx.compose.ui:ui-graphics | 1.3.0 | 1.3.1 | 1.3.2 | 1.3.3 |
androidx.compose.ui:ui-test | 1.3.0 | 1.3.1 | 1.3.2 | 1.3.3 |
androidx.compose.ui:ui-test-junit4 | 1.3.0 | 1.3.1 | 1.3.2 | 1.3.3 |
androidx.compose.ui:ui-test-manifest | 1.3.0 | 1.3.1 | 1.3.2 | 1.3.3 |
androidx.compose.ui:ui-text | 1.3.0 | 1.3.1 | 1.3.2 | 1.3.3 |
androidx.compose.ui:ui-text-google-fonts | 1.3.0 | 1.3.1 | 1.3.2 | 1.3.3 |
androidx.compose.ui:ui-tooling | 1.3.0 | 1.3.1 | 1.3.2 | 1.3.3 |
androidx.compose.ui:ui-tooling-data | 1.3.0 | 1.3.1 | 1.3.2 | 1.3.3 |
androidx.compose.ui:ui-tooling-preview | 1.3.0 | 1.3.1 | 1.3.2 | 1.3.3 |
androidx.compose.ui:ui-unit | 1.3.0 | 1.3.1 | 1.3.2 | 1.3.3 |
androidx.compose.ui:ui-util | 1.3.0 | 1.3.1 | 1.3.2 | 1.3.3 |
androidx.compose.ui:ui-viewbinding | 1.3.0 | 1.3.1 | 1.3.2 | 1.3.3 |
最新的版本信息可以通过官方的链接进行查看BoM 到库的版本映射 | Android Developers
除此之外,还需要注意与kotiln的版本对应关系,BOM的各版本兼容的最低Kotlin版本可是有所不同的!详情见下文
compose版本与Kotlin的兼容性
参考
- Android Compose BoM 物料清单_抓饼先生的博客-CSDN博客
- 快速入门 | Jetpack Compose | Android Developers
- compose版本与Kotlin的兼容性
- BoM 到库的版本映射 | Android Developers
最新文章
- SQL优化技术分析-3:SQL语句索引的利用
- PHP中面向对象的关键字
- Leetcode 35 Search Insert Position 二分查找(二分下标)
- 小白科普之JavaScript的函数
- iOS的runtime(转)
- 【BZOJ】1798: [Ahoi2009]Seq 维护序列seq(线段树)
- Dire Wolf ---hdu5115(区间dp)
- iphone练习之手势识别(双击、捏、旋转、拖动、划动、长按)UITapGestureRecognizer
- MTK MOTA升级步骤
- 移动 云MAS 发短信 .net HTTP 请求
- 剑指Offer-按之字形顺序打印二叉树
- Dynamics CRM 安装Microsoft Dynamics CRM Reporting Extensions
- 20170831工作日记--自定义View学习
- S3C2440时钟体系结构
- 面向对象编程思想(前传)--你必须知道的javascript(转载)
- Memcached Windows 测试
- 自动化测试的组成部分:SEARCH
- Quartz_2_简单编程式任务调度使用(CronTrigger)
- vs2015发布网站至azure web应用服务
- (转)使用Cobbler批量部署Linux和Windows:Cobbler服务端部署(一)
热门文章
- 你听说过OTA吗?
- [C# 中的序列化与反序列化](.NET 源码学习)
- HDC.Cloud Day | 全国首场上海站告捷,聚开发者力量造梦、探梦、筑梦
- PEP8语法规范解释说明
- c++题目:数迷
- JavaEE Day13 Tomcat和Servlet
- 【Java SE】Day03流程控制语句
- 【每日一题】【判断栈是否为空的方法】2022年1月9日-NC76 用两个栈实现队列的出队入队【入队简单】
- 【CDH数仓】Day02:业务数仓搭建、Kerberos安全认证+Sentry权限管理、集群性能测试及资源管理、邮件报警、数据备份、节点添加删除、CDH的卸载
- DC-9靶场练习