Android has been Kotlin-first for four years and many Android developers have made the switch resulting in higher productivity and more stable apps. Although the default language for defining builds is Groovy (build.gradle), even if a Kotlin (build.gradle.kts) option has been present in Gradle for many years.
Today we are happy to announce that we are changing the default language for build scripts to Kotlin! This means that Kotlin is the single default language used for all project code, including the UI. jetpack design, and create the script now! We are working with the Gradle and JetBrains teams on this improvement, and you can read more in their respective announcements: gradle blog, jetbrains blog,
This does not affect existing projects using Groovy, as they will continue to work without any plans for deprecation. But if you are creating new project or module starting with Android Studio Giraffe, now you will get Kotlin DSL by default. The updated project template is an easy way to get started with the new Kotlin DSL build scripts. To migrate an existing build, see Kotlin DSL Migration Guide,
While Kotlin DSL is the default for new projects, migrating large, existing Groovy DSL based projects should wait while Gradle, JetBrains and Google work on further improving build performance. This is a work in progress and we’ll share updates as we move forward. In particular, script compilation performance is slow compared to Groovy DSL. However, unlike Groovy DSLs, Kotlin DSL script compilation results are stored in the Gradle local and remote caches so that subsequent builds do not require recompilation.
Having a single language for all code in a project isn’t the only benefit of this change, so let’s take a look at some of the other great things about using the Kotlin DSL for Gradle builds.
- Kotlin is statically typed so you get quick and accurate code hints when editing Kotlin DSL build scripts:
- The syntax errors are more precise, and they appear when editing a Kotlin DSL build script, rather than trying to sync the project:
- Get the Type and Method docs by pressing Control+Q (Command+B on macOS). If you need more details you can jump to the underlying source code by pressing Control+Click (Command+Click):
- You can mix Groovy DSL build scripts and Kotlin DSL build scripts in one project and migrate incrementally module by module. This enables new modules to use the Kotlin DSL while keeping existing modules on Groovy.
A related change we’re also making to the new project template is an experimental option to use gradle version catalog With Kotlin DSL build script.
Version catalogs give you a centralized, scalable way to define your project’s dependencies. While the use of version catalogs is optional, they pair well with Kotlin DSLs by providing more type safety in your build definitions.
To learn about migrating to the version catalog, see migration guide,