当前位置:网站首页>在应用中使用 Jetpack 库
在应用中使用 Jetpack 库
2022-07-25 23:22:00 【Cola可洛】
在应用中使用 Jetpack 库
所有 Jetpack 组件都可在 Google Maven 代码库中找到。
打开 settings.gradle 文件,将 google() 代码库添加到 dependencyResolutionManagement { repositories {...}} 块中,如下所示:
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
google()
jcenter()
}
}
然后,您可以在模块的 build.gradle 文件中添加 Jetpack 组件(例如 LiveData 和 ViewModel 等架构组件),如下所示:
dependencies {
def lifecycle_version = "2.2.0"
implementation "androidx.lifecycle:lifecycle-livedata-ktx:$lifecycle_version"
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:$lifecycle_version"
...
}
许多 Jetpack 库都提供Android KTX 扩展 ,如上面的 lifecycle-livedata-ktx 和 lifecycle-viewmodel-ktx 所示。KTX 扩展在基于 Java 的 API 基础上构建,充分利用了 Kotlin 特有的语言功能。
如需了解新的 Jetpack 库版本,请查看版本信息页面。
基于 Kotlin 以及基于 Java 的 API参考文档页面适用于所有 Jetpack 库。
边栏推荐
- chown: changing ownership of ‘/var/lib/mysql/‘: Operation not permitted
- Serialize addition, deletion, modification and query
- Rendering, filtering (filtering) and sorting of lists
- Node基础
- 学习探索-波浪
- npm+模块加载机制
- CSV generated by PHP cannot completely display the number with leading 0
- Kotlin 常用知识点汇总
- Cuteone: a onedrive multi network disk mounting program / with member / synchronization and other functions
- R language drawing parameters (R language plot drawing)
猜你喜欢

生成随机数random学习之uniform_int_distribution,uniform_real_distribution

Cuteone: a onedrive multi network disk mounting program / with member / synchronization and other functions

Learning exploration-3d rotation card

学习探索-波浪

VisualBox启动虚拟机报错:The VM session was closed before any attempt to power it on.

npm+模块加载机制

@Import

【代码案例】博客页面设计(附完整源码)

谷粒学苑P98踩坑 e.GlobalExceptionHandler : null

How to set pseudo static for WordPress fixed links
随机推荐
Overview of MES system equipment management (Part 2)
[wechat applet] page navigation
关于优先队列
Moment.js
理解的英文(言语理解)
Secure code warrior learning record (IV)
@Autowired annotation required attribute
Learning exploration - waves
chown: changing ownership of ‘/var/lib/mysql/‘: Operation not permitted
@Import
initializer_list工具库学习
TS union type
推荐系统——An Embedding Learning Framework for Numerical Features in CTR Prediction
Which securities company should a novice choose to open an account? Is it safe?
Kotlin 常用知识点汇总
The difference between MySQL clustered index and non clustered index
Recommended system - an embedded learning framework for numerical features in CTR prediction
JS regular expression content:
Firewall command simple operation
Recursion of function (use recursion to find the factorial of 1-N) (use recursion to find Fibonacci sequence) (use recursion to traverse data)