Paul Krill
Editor at Large

Google Android team embraces Rust for Android OS development

news
Apr 9, 20213 mins

The Android Open Source Project has adopted the Rust programming language for use in new Android OS development, citing its memory safety advantages over C/C++.

rust king iron bronze crown royal queen
Credit: Gratisography

Looking to prevent memory bugs, the Android Open Source Project now supports the Rust language for development of the Android mobile OS itself, taking on development tasks that have been the domain of C/C++.

In a Google blog post on April 6, members of the Android team stressed that correctness of code in Android was a top priority for security, stability, and quality. Memory safety bugs are a top contributor to stability issues, representing about 70 percent of high-severity security vulnerabilities in Android; safety bugs in C and C++ continue to be the most difficult to address. Rust provides memory safety guarantees by leveraging compile-time checks to enforce object lifetime checks to ensure that memory accesses are valid, Android team members said. Further, Rust achieves this safety while providing performance equivalent to C and C++.

Rust joins a list of memory-safe languages for Android OS development that also includes Java and Kotlin. While the Android OS uses Java extensively to protect large portions of the platform from memory bugs, neither Java nor Kotlin are an option for lower layers of the OS. These layers require languages like C, C++, and Rust, which offer predictable performance in resource-constrained environments. Further, with C and C++, developers must manage memory lifecycles themselves, which is prone to mistakes, especially when working with complex, multithreaded codebases. Rust manages memory use automatically.

C and C++ lack the same memory safety guarantees as Rust and require robust isolation. All Android processes are sandboxed and builders of the OS follow the “rule of two” guideline for code safety (namely, choose only two: code that handles untrustworthy inputs, code that uses unsafe implementation languages such as C and C++, or code that runs with no sandbox). While this rule reduces the severity of security vulnerabilities, it has limitations. Sandboxing is expensive, consuming overhead and producing latency, while not eliminating vulnerabilities from code.

Memory-safe languages like Rust overcome these limitations, lowering the density of bugs in code, increasing the effectiveness of current sandboxing, reducing the need to sandbox, and enabling introduction of new features that are safer and lighter on resources.

The Android team’s memory-safety efforts will be focused on new development rather than rewriting mature C/C++ code. Most memory bugs occur in new or recently modified code. Team members also cautioned that adding a new language to the Android platform is a large undertaking, with toolchains and dependencies that need to be maintained, and test infrastructure and tooling needing to be updated. Also, developers have to be trained.

Rust support has been added to the Android Open Source Project during the past 18 months, with some early adopter projects to be revealed soon.

Paul Krill

Paul Krill is editor at large at InfoWorld. Paul has been covering computer technology as a news and feature reporter for more than 35 years, including 30 years at InfoWorld. He has specialized in coverage of software development tools and technologies since the 1990s, and he continues to lead InfoWorld’s news coverage of software development platforms including Java and .NET and programming languages including JavaScript, TypeScript, PHP, Python, Ruby, Rust, and Go. Long trusted as a reporter who prioritizes accuracy, integrity, and the best interests of readers, Paul is sought out by technology companies and industry organizations who want to reach InfoWorld’s audience of software developers and other information technology professionals. Paul has won a “Best Technology News Coverage” award from IDG.

More from this author