How to add Android Kotlin files to a Cordova Plugin project

add the following in config.xml

<preference name="GradlePluginKotlinEnabled" value="true" />
<preference name="GradlePluginKotlinCodeStyle" value="official" />
<preference name="GradlePluginKotlinVersion" value="1.3.50" />

also note where to put the kotlin files, i.e. src/main/kotlin///


<source-file src="src/android/file.kt" target-dir="app/src/main/kotlin/xx/yy/zz" />

and add the below to your plugin's if the kotlin files aren't picked up by your project

android {
    sourceSets { {
            srcDirs += 'src/main/kotlin'

This answer is referenced from:

I modifed an example repository to test this:

Kotlin support was added in Cordova 9.0.0, which was released on January 23 2020. Here you can find more information: