Migrating Gradle to Kotlin DSL in Android Studio 3.3

Cheat sheet for migrating Gradle files from Groovy to Kotlin

Image for post
Image for post

Note: In this article I assume that you know what Kotlin has to do with Gradle and are just looking for a quick cheat sheet or a copy-paste solution. For a complete documentation take a look here.

Step one: Gradle Wrapper Version

It is recommended to use Wrapper from version 5.0 and upwards, unfortunately in Android projects it is at the same time strongly recommended to avoid the use of Gradle 5.0 without Android Gradle Plugin 3.4 (which is not yet released). In this case, just make sure that you are using newest supported Wrapper version (4.10.1 at the time of writing).

Step two: Change all to

Using the Find and replace (ctrl + R in android studio) tool change all single quoted strings (‘) to double quoted strings (“) in all your Gradle files. For freshly started apps you have to take care of three files:

  • settings.gradle
  • build.gradle (Project)
  • build.gradle (Module)

Step three: Change implicit assignments and function calls into explicit ones

Now, all Groovy assignments and function calls have to be changed into Kotlin-friendly fashion. Replace all of them as shown below:

If you don’t know what, how or even if something should be changed in this step, take a look at the example files linked at the bottom of this article.

Step four: Migrate settings.gradle

Note: Before doing this you might want to turn-off the auto-sync for Gradle files as it might cause you to go crazy. Turn it on again after you’ve completed migration for the whole project.

Using Rename file (shift + F6) tool change the name of settings.gradle file to settings.gradle.kts. For fresh projects it should look like this:

Step five: Migrate build.gradle (Project)

Repeat the step as above but for the project’s build.gradle file. Change its name to build.gradle.kts.

Step six: Migrate settings.gradle (Module)

And once again, do the same for module’s build.gradle -> build.gradle.kts.

Links for example files:

Examples of working Gradle files can be found at my github repository. Feel free to either fork or copy them at any time.

If you are facing any problems with migration, remember to always follow the errors shown in the build/sync logs, not the ones shown by Android Studio as it is still far from perfect when it comes to that.

Written by

I’m an Android/Kotlin-Multiplatform developer. I write about technologies and patterns I use in my everyday job.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store