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 |

相关推荐
whoarethenext3 分钟前
使用 C++/OpenCV 和 MFCC 构建双重认证智能门禁系统
开发语言·c++·opencv·mfcc
雨白10 分钟前
Jetpack系列(三):Room数据库——从增删改查到数据库平滑升级
android·android jetpack
代码的奴隶(艾伦·耶格尔)1 小时前
后端快捷代码
java·开发语言
Jay_5151 小时前
C++多态与虚函数详解:从入门到精通
开发语言·c++
路来了1 小时前
Python小工具之PDF合并
开发语言·windows·python
xiaolang_8616_wjl2 小时前
c++文字游戏_闯关打怪
开发语言·数据结构·c++·算法·c++20
WJ.Polar2 小时前
Python数据容器-list和tuple
开发语言·python
FrostedLotus·霜莲2 小时前
C++主流编辑器特点比较
开发语言·c++·编辑器
超级码.里奥.农2 小时前
零基础 “入坑” Java--- 七、数组(二)
java·开发语言
KENYCHEN奉孝3 小时前
Rust征服字节跳动:高并发服务器实战
服务器·开发语言·rust