要開(kāi)始使用Compose,需要先向項(xiàng)目中添加一些 build 配置。
將以下定義添加到應(yīng)用的build.gradle.kts文件中:
android {
buildFeatures {
compose = true
}
composeOptions {
kotlinCompilerExtensionVersion = "1.5.9"
}
}
此外,請(qǐng)將以下部分中您需要的Compose BoM和Compose庫(kù)依賴項(xiàng)的子集添加到您的依賴項(xiàng):文章來(lái)源:http://www.zghlxwxcb.cn/news/detail-832536.html
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 的兼容性對(duì)應(yīng)關(guān)系:文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-832536.html
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 |
到了這里,關(guān)于Compose的gradle配置以及與Kotlin的兼容對(duì)應(yīng)的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!