路径可在SDK Manager的"SDK Tools"中查看NDK安装位置。
##### 3. Kotlin项目依赖配置
Kotlin项目需确保正确配置插件与依赖,以`architecture-samples`中的Kotlin模块为例:
1. **添加Kotlin插件**:在模块级`build.gradle`的`plugins`块中添加:
```gradle
plugins {
id 'com.android.application'
id 'org.jetbrains.kotlin.android' // Kotlin Android插件
id 'kotlin-kapt' // Kotlin注解处理器(替代annotationProcessor)
}
-ktx为后缀,如core-ktx、lifecycle-runtime-ktx,示例依赖配置:
dependencies {
implementation "androidx.core:core-ktx:1.10.1" // Kotlin扩展核心库
implementation "androidx.lifecycle:lifecycle-runtime-ktx:2.6.0" // 生命周期KTX
kapt "androidx.room:room-compiler:2.5.2" // Room注解处理器(使用kapt)
}
若需开发Compose UI项目,按以下步骤创建:
Compose项目依赖需在模块级build.gradle中配置,典型示例:
dependencies {
implementation "androidx.compose.ui:ui:$compose_version"
implementation "androidx.compose.material3:material3:$compose_version"
implementation "androidx.compose.ui:ui-tooling-preview:$compose_version"
debugImplementation "androidx.compose.ui:ui-tooling:$compose_version"
}
ext {
compose_version = '1.4.3' // 使用最新稳定版,参考[0]
}
完成配置后,建议通过以下方式验证环境完整性:
通过以上步骤,即可搭建稳定高效的Kotlin for Android开发环境,为后续项目实战奠定基础。