Google has detailed significant improvements that the Google Home team achieved just by rewriting the Google Home app in the modern programming language Kotlin.
Google is encouraging all Android developers to use Kotlin after its 2019 announcement that Android development will from here on be "Kotlin-first" as opposed to Java, which was historically the prioritized language for Android app development.
Announcing a new free beginner's Kotlin Android development course last week, Google claimed that 70% of the top 1,000 Android apps are written in Kotlin and one of them is from the team that develops the Google Home Android app.
The Google Home app isn't completely written in Kotlin yet, but as of June about 30% of the code base was rewritten in Kotlin from the legacy Java code. Kotlin is also being encouraged for all new features in the app.
The switch to Kotlin has had two major effects. First, it's reduced the number of NullPointerExceptions by 33% thanks to Kotlin's type system. This type of error is the largest cause of app crashes on Google Play, so reducing these can have a major impact on how users experience Android apps.
"Because Kotlin can make nullability a part of the language, tricky situations can be avoided, like when inconsistent usage of nullability annotations in Java might lead to a missed bug," Google explains.
Kotlin has also helped Google's Home app developers become more productive as it requires much less code compared to the equivalent of existing Java code. Google point's to the use of data classes and the Parcelize plugin as an example.
"A class which was 126 hand-written lines in Java can now be represented in just 23 lines in Kotlin—an 80% reduction," the company says.
The Google Home app has over one million lines of code, so to simplify development the team is taking advantage of Jetpack, a suite of libraries Google developed to improve app quality with less code.
The Google Home team has gradually added Jetpack libraries that replace custom solutions. Since these libraries help developers code in a less verbose manner, it has helped make the code more readable for developers analyzing code previously written by other team members.
The promotion of Kotlin, which was created by Czech-based IDE maker JetBrains, is all part of Google's commitment to the language for Android app development.
Under Google's Kotlin-first policy, the company has committed to providing better support to Kotlin. While the Android Studio IDE supports both Kotlin and Java, Jetpack libraries exclusively support Kotlin and new online-training material and samples, which are definitely available for Kotlin only may be available for Java. Google currently has 60 apps written in Kotlin, including Maps, Home, Play, Pay, and Drive.