Java 로 코딩된 프로젝트에 코틀린 코드 일부를 추가하는 걸 테스트 해보고 간단하게 적어둔다.
프로젝트 build.gradle
buildscript { ext.kotlin_version = '1.3.71' repositories { google() jcenter() } dependencies { classpath 'com.android.tools.build:gradle:3.6.1' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" } }
|
앱 build.gradle
apply plugin: 'com.android.application' // 코틀린 혼용 사용을 위해 추가 apply plugin: 'kotlin-android' apply plugin: 'kotlin-android-extensions' apply plugin: 'kotlin-kapt'
android { compileSdkVersion 29 buildToolsVersion "29.0.3"
defaultConfig { applicationId "com.link2me.android.javakotlin" minSdkVersion 23 targetSdkVersion 29 versionCode 1 versionName "1.0"
}
buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' } }
compileOptions { sourceCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8 }
}
dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" // 코틀린 혼용 사용을 위해 추가 implementation 'androidx.appcompat:appcompat:1.1.0' implementation 'androidx.constraintlayout:constraintlayout:1.1.3' implementation 'androidx.annotation:annotation:1.1.0'
implementation 'com.google.android.material:material:1.0.0' implementation 'androidx.recyclerview:recyclerview:1.1.0' implementation 'androidx.cardview:cardview:1.0.0' implementation 'gun0912.ted:tedpermission:2.0.0'
implementation 'com.squareup.retrofit2:retrofit:2.7.0' implementation 'com.squareup.retrofit2:converter-gson:2.7.0' implementation 'com.squareup.okhttp3:logging-interceptor:4.4.0' }
|
Java 코드 파일과 kotlin 코드 파일을 혼용하여 사용해봤는데 잘 동작하는 걸 확인할 수 있었다.
코틀린을 완벽하게 이해한 상태이면 Java 코드 필요없겠지만 코틀린 문법 공부 하다 말아서 이렇게라도 해보는 것이 의의가 있다.