How to use Java and Kotlin together in android
2. Add dependencies of "kotlin-gradle-plugin" in build.gradle (Project level)
dependencies {
classpath "com.android.tools.build:gradle:$agp_version"
classpath 'com.google.gms:google-services:4.3.5'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
// Add the Crashlytics Gradle plugin
classpath 'com.google.firebase:firebase-crashlytics-gradle:2.7.1'
//kotlin
classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.0' //here
}
3. Add kotlin plugin id in build.gradle (App level)
plugins {
id 'com.android.application'
id 'kotlin-android'
}
4. Add sourceSets for kotlin file
android {
compileSdkVersion 34
buildToolsVersion "30.0.3"
defaultConfig {
applicationId "org.techtown.volleyball"
minSdkVersion 21
targetSdkVersion 34
multiDexEnabled true
versionCode 16
versionName "1.2.11"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_11
targetCompatibility JavaVersion.VERSION_11
}
buildFeatures {
viewBinding true
}
sourceSets {
main.java.srcDirs += 'src/main/kotlin' //here
}
}
5. Add kotlin dependencies in build.gradle (App level)
dependencies {
//kotlin
implementation 'org.jetbrains.kotlin:kotlin-stdlib:1.6.0'
}
6. Sync gradle file and wrie kotlin code.
댓글 없음:
댓글 쓰기