面试题答案
一键面试- 引入Kotlin插件:
在项目根目录的
build.gradle
文件中,确保buildscript
的dependencies
块引入Kotlin插件。例如:
buildscript {
dependencies {
classpath "org.jetbrains.kotlin:kotlin - gradle - plugin:$kotlin_version"
}
}
其中$kotlin_version
是你要使用的Kotlin版本号。
- 应用Kotlin插件:
在React Native模块的
build.gradle
文件中,应用Kotlin插件。例如:
apply plugin: 'kotlin - android'
- 配置Kotlin源集:
在模块的
build.gradle
文件中,配置Kotlin源集路径。例如:
sourceSets {
main {
kotlin {
srcDirs 'src/main/kotlin'
}
}
}
- 添加Kotlin依赖:
添加Kotlin标准库依赖。在模块的
build.gradle
文件的dependencies
块中添加:
dependencies {
implementation "org.jetbrains.kotlin:kotlin - stdlib - jdk8:$kotlin_version"
}
- 配置编译选项:
设置Kotlin编译选项,确保与项目的其他部分兼容。例如,在模块的
build.gradle
文件中:
kotlinOptions {
jvmTarget = "1.8"
}