Migrate Android build configuration from Groovy to Kotlin

Posted on Apr 8, 2022

Here are the steps I did when I migrated our Android build to Kotlin. Long story short, the reasons for migration is the syntax highlighting and built-in support with Android Studio.

I searched for all single quotes and replaced them with double quotes.

Migrate to function invocations in Kotlin syntax. As you noticed the parenthesis.

Rename file settings.gradle to settings.gradle.kts

Inside settings.gradle.kts, refactor code from

include ':app'
rootProject.name='OnlineJobs'

to

include (":app", ":OnlineJobs")

Take note you need to replace it with your own app project name (instead of OnlineJobs). And then sync Gradle.

The next step is to rename the project level build.gradle to build.gradle.kts.

After migrating, rename also the app-level build.gradle to build.gradle.kts, Android Studio was throwing errors Module not specified or app wasn’t found in the Edit Configurations menu. The solution was to change the syntax of repositories from

repositories {
    maven {
        val url = "https://plugins.gradle.org/m2/"
    }
    google()
    mavenCentral()
}

maven {
    val url = "https://plugins.gradle.org/m2/"
}

to

repositories {
    maven {
        url = uri("https://plugins.gradle.org/m2/")
    }
    google()
    mavenCentral()
}

Take note of the uri() method.

And that's it. If you have any questions, you can email me at hello@lwgmnz.me.