Compose的gradle配置以及与Kotlin的兼容对应

要开始使用Compose,需要先向项目中添加一些 build 配置。

将以下定义添加到应用的build.gradle.kts文件中:

Kotlin 复制代码
android {
    buildFeatures {
        compose = true
    }

    composeOptions {
        kotlinCompilerExtensionVersion = "1.5.9"
    }
}

此外,请将以下部分中您需要的Compose BoM和Compose库依赖项的子集添加到您的依赖项:

Kotlin 复制代码
dependencies {

    val composeBom = platform("androidx.compose:compose-bom:2024.02.00")
    implementation(composeBom)
    androidTestImplementation(composeBom)

    // Choose one of the following:
    // Material Design 3
    implementation("androidx.compose.material3:material3")
    // or Material Design 2
    implementation("androidx.compose.material:material")
    // or skip Material Design and build directly on top of foundational components
    implementation("androidx.compose.foundation:foundation")
    // or only import the main APIs for the underlying toolkit systems,
    // such as input and measurement/layout
    implementation("androidx.compose.ui:ui")

    // Android Studio Preview support
    implementation("androidx.compose.ui:ui-tooling-preview")
    debugImplementation("androidx.compose.ui:ui-tooling")

    // UI Tests
    androidTestImplementation("androidx.compose.ui:ui-test-junit4")
    debugImplementation("androidx.compose.ui:ui-test-manifest")

    // Optional - Included automatically by material, only add when you need
    // the icons but not the material library (e.g. when using Material3 or a
    // custom design system based on Foundation)
    implementation("androidx.compose.material:material-icons-core")
    // Optional - Add full set of material icons
    implementation("androidx.compose.material:material-icons-extended")
    // Optional - Add window size utils
    implementation("androidx.compose.material3:material3-window-size-class")

    // Optional - Integration with activities
    implementation("androidx.activity:activity-compose:1.8.2")
    // Optional - Integration with ViewModels
    implementation("androidx.lifecycle:lifecycle-viewmodel-compose:2.6.1")
    // Optional - Integration with LiveData
    implementation("androidx.compose.runtime:runtime-livedata")
    // Optional - Integration with RxJava
    implementation("androidx.compose.runtime:runtime-rxjava2")

}

以下是Compose 与 Kotlin 的兼容性对应关系

|---------------------|---------------|
| Compose Compiler 版本 | 兼容的 Kotlin 版本 |
| 1.5.9 | 1.9.22 |
| 1.5.8 | 1.9.22 |
| 1.5.7 | 1.9.21 |
| 1.5.6 | 1.9.21 |
| 1.5.5 | 1.9.20 |
| 1.5.4 | 1.9.20 |
| 1.5.3 | 1.9.10 |
| 1.5.2 | 1.9.0 |
| 1.5.1 | 1.9.0 |
| 1.5.0 | 1.9.0 |
| 1.4.8 | 1.8.22 |
| 1.4.7 | 1.8.21 |
| 1.4.6 | 1.8.20 |
| 1.4.5 | 1.8.20 |
| 1.4.4 | 1.8.10 |
| 1.4.3 | 1.8.10 |
| 1.4.2 | 1.8.10 |
| 1.4.1 | 1.8.0 |
| 1.4.0 | 1.8.0 |

相关推荐
一个响当当的名号2 分钟前
c++primer 个人学习总结-模板和泛型编程
开发语言·c++·学习
落羽的落羽2 分钟前
【C++】C++11的可变参数模板、emplace接口、类的新功能
开发语言·c++·学习
滴滴滴嘟嘟嘟.4 分钟前
Qt对话框与文件操作学习
开发语言·qt·学习
andyguo29 分钟前
AI模型测评平台工程化实战十二讲(第一讲:从手工测试到系统化的觉醒)
android
2501_9159214332 分钟前
小团队如何高效完成 uni-app iOS 上架,从分工到工具组合的实战经验
android·ios·小程序·uni-app·cocoa·iphone·webview
幂简集成1 小时前
通义灵码 AI 程序员低代码 API 课程实战教程
android·人工智能·深度学习·神经网络·低代码·rxjava
liulilittle1 小时前
HTTP简易客户端实现
开发语言·网络·c++·网络协议·http·编程语言
程序员皮皮林1 小时前
Java jar 如何防止被反编译?代码写的太烂,害怕被人发现
java·开发语言·jar
qczg_wxg2 小时前
高阶组件介绍
开发语言·javascript·react native·ecmascript
2501_916008892 小时前
uni-app iOS 文件管理与 itools 配合实战,多工具协作的完整流程
android·ios·小程序·https·uni-app·iphone·webview