Skip to main content

Google Home for Android seeing fewer crashes after adopting Kotlin

At I/O 2017, Kotlin became an officially-supported programming language for Android, and last year, Google encouraged developers to use it over Java. The Google Home app is migrating over, with end-users benefiting from a reduction in crashes.

The Google Home case study was presented as part of “Languages” week during the 11 Weeks of Android series. As of last month, 30% of the smart home companion app’s code base — of which there are “over a million lines of code” —  is written in Kotlin, and the language is now “encouraged for all new features.”

In using Kotlin, the team wanted to make their “programming more productive” and take advantage of modern features. The switch has seen a reduction “in the amount of required code, compared to the equivalent of existing Java code.”

One example is the use of data classes and the Parcelize plugin: a class which was 126 hand-written lines in Java can now be represented in just 23 lines in Kotlin—an 80% reduction.

Meanwhile, the switch to Kotlin has resulted in a 33% reduction in the Google Home app’s most common crash type:

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. Since the team started migrating to developing new features with Kotlin, they saw a 33% decrease in NullPointerExceptions. 

The team is also gradually adding Jetpack libraries to replace custom-tailored code, thus helping reduce the need for boilerplate code maintenance 

Incorporating them allowed the team to consolidate and replace custom tailored solutions, sometimes even with a single library. Since Jetpack libraries can help engineers follow best practices and be less verbose (for example, using Room or ConstraintLayout), readability was increased as well. The team considers many of the newer Jetpack libraries ‘must-haves,’ including ViewModel and LiveData, both of which are used extensively in the Google Home codebase.

Google today also launched a free “Android Basics in Kotlin” online course aimed at “people without programming experience.”

In this five-unit course, you learn the basics of building Android apps with the Kotlin programming language and develop a collection of simple apps to start your journey as an Android developer.

FTC: We use income earning auto affiliate links. More.

You’re reading 9to5Google — experts who break news about Google and its surrounding ecosystem, day after day. Be sure to check out our homepage for all the latest news, and follow 9to5Google on Twitter, Facebook, and LinkedIn to stay in the loop. Don’t know where to start? Check out our exclusive stories, reviews, how-tos, and subscribe to our YouTube channel

Comments

Author

Avatar for Abner Li Abner Li

Editor-in-chief. Interested in the minutiae of Google and Alphabet. Tips/talk: abner@9to5g.com