Migrate Android build configuration from Groovy to Kotlin

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 [email protected].

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

  You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

  You are commenting using your Twitter account. Log Out /  Change )

  You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s