How to add Kotlin support for regular Java Lib in Android?

When we want to use Kotlin in Android Studio, it's pretty simple. Add the kotlin dependent library, and also add the Kotlin-Android plugin below:

 apply plugin: 'com.android.library'
 apply plugin: 'kotlin-android'

However, if I have a regular library (used for Java) and you want to write in Kotlin, should I add some kind of plugin? The below is definitely not working.

 apply plugin: 'java-library'
 apply plugin: 'kotlin-android'

There is no kotlin-library that I find to add. What should I add to my gradle module so that it can compile Kotlin?

+4
source share
2 answers

You only need to add the Kotlin plugin:

apply plugin: "kotlin"

java-library Gradle java. kotlin, .

+3

,

apply plugin: 'kotlin'

compile "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version" 

kotlin, kotlin . . @JvmStatic ..

build.gradle kotlin :

apply plugin: 'kotlin'

repositories {
    mavenCentral()
}

dependencies {
    compile "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
}

$kotlin_version build.gradle.

Idea Android Studio ( Android Studio 3.0 Beta 2) app.

0

Source: https://habr.com/ru/post/1683673/


All Articles