In an effort to ensure Android is secure and stable, Google has announced the Android Open Source Project (AOSP) will support Rust for developing the operating system. According to the company, memory safety bugs continue to plague code and memory-safe programming languages like Kotlin, Java and Rust help prevent these bugs from happening in the first place. 

“Rust provides memory safety guarantees by using a combination of compile-time checks to enforce object lifetime/ownership and runtime checks to ensure that memory accesses are valid. This safety is achieved while providing equivalent performance to C and C++,” Jeff Vander Stoep and Stephen Hines from the Android Team wrote in a post

RELATED CONTENT: What’s all the fuss about Rust?

Google uses Java and Kotlin languages for Android app development due to their ease of use, portability and safety. The Android operating system uses Java to prevent memory bugs, but the lower layers of the OS require languages such as C, C++ and Rust, Stoep and Hines explained.

“These languages are designed with control and predictability as goals. They provide access to low level system resources and hardware. They are light on resources and have more predictable performance characteristics,” they wrote. 

However, Stoep and Hines explained it is easy to make mistakes in C and C++ and comes with limitations such as the need to consume additional overhead and introduce latency. 

With Rust, Google is able to lower the density of bugs, increase the effectiveness of sandboxing, reduce the need for sandboxing, and introduce new features that are safer and lighter on resources. 

The team noted that introducing a new language will not introduce bugs in its existing C and C++ code, and that the older code is not where the company needs to improve. 

“Adding a new language to the Android platform is a large undertaking. There are toolchains and dependencies that need to be maintained, test infrastructure and tooling that must be updated, and developers that need to be trained. For the past 18 months we have been adding Rust support to the Android Open Source Project, and we have a few early adopter projects that we will be sharing in the coming months. Scaling this to more of the OS is a multi-year project,” the team wrote.