Android java项目添加kotlin混合开发环境配置

Android Studio java代码中添加kotlin混合开发

1.项目的build.gradle中添加kotlin-gradle-plugin

buildscript {
    repositories {
        google()
        jcenter()
        
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:7.3.1'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.7.20"
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

2.模块的build.gradle中应用kotlin插件和添加依赖库

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-android'

dependencies {
    implementation 'androidx.core:core-ktx:1.0.2'
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.7.20"
}
 

你可能感兴趣的:(android,kotlin,java)