2025년 3월 27일부터 AOSP를 빌드하고 기여하려면 aosp-main
대신 android-latest-release
를 사용하는 것이 좋습니다. 자세한 내용은 AOSP 변경사항을 참고하세요.
Android Rust 소개
컬렉션을 사용해 정리하기
내 환경설정을 기준으로 콘텐츠를 저장하고 분류하세요.
Android 플랫폼은 C/C++과 동급의 성능으로 메모리 안전 보장을 제공하는 최신 시스템 프로그래밍 언어인 Rust에서 네이티브 OS 구성요소를 개발하기 위한 지원을 제공합니다. Rust는 객체 수명 및 소유권을 적용하는 컴파일 시간 검사와 유효한 메모리 액세스를 보장하는 런타임 검사를 모두 사용함으로써 가비지 컬렉터를 사용할 필요를 없애 줍니다.
Rust는 개발자가 높은 생산성으로 코드에 확신을 가질 수 있도록 지원하는 다양한 최신 언어 기능을 제공합니다.
- 안전한 동시 프로그래밍 - 손쉽게 안전한 동시 프로그래밍을 진행하여 사용자가 효율적인 스레드 안전 코드를 작성할 수 있도록 지원하는 기능은 Rust의 Fearless Concurrency(두려움 없는 동시성)라는 슬로건에 반영되어 있습니다.
- 명시적 형식 시스템 - 명시적인 형식(Newtype 래퍼, 콘텐츠를 갖는 enum 옵션 등)이 허용되므로 논리적인 프로그래밍 버그를 방지할 수 있습니다.
- 강력한 컴파일 시간 검사 - 컴파일 시간에 더 많은 버그를 발견하는 경우 개발자는 코드가 성공적으로 컴파일된다면 의도한 대로 작동한다는 확신을 가질 수 있습니다.
- 내장된 테스트 프레임워크 - Rust는 테스트 대상 구현 옆에 단위 테스트를 배치하여 더 쉽게 단위 테스트를 포함할 수 있는 내장된 테스트 프레임워크를 제공합니다.
- 오류 처리 적용 - 복구 가능한 오류가 있는 함수는 Result 형식(성공 옵션 또는 오류 옵션)을 반환할 수 있습니다. 컴파일러는 호출자가 함수 호출에서 반환된
Result
enum의 오류 옵션을 검사하고 처리하도록 요구합니다. 이를 통해 처리되지 않은 오류로 인해 버그가 발생할 가능성이 줄어듭니다.
- 초기화 - Rust에서는 모든 변수를 사용하기 전에 변수 형식의 정상 멤버로 초기화해야 합니다. 이로 인해 실수로 안전하지 않은 값으로 초기화되는 일이 방지됩니다.
- 안전한 정수 처리 - 모든 정수 형식 변환은 명시적 변환으로 이루어집니다.
함수 호출 중에 변수에 할당할 때나 다른 형식과 함께 연산을 시도할 때 개발자가 실수로 변환할 수 없습니다. Android에서는 기본적으로 Rust용 오버플로 검사가 설정되어 있으며, 이에 따라 오버플로 연산이 명시적으로 이루어져야 합니다.
자세한 내용은 Android Rust 지원에 관한 블로그 게시물 시리즈를 참고하세요.
이 페이지에 나와 있는 콘텐츠와 코드 샘플에는 콘텐츠 라이선스에서 설명하는 라이선스가 적용됩니다. 자바 및 OpenJDK는 Oracle 및 Oracle 계열사의 상표 또는 등록 상표입니다.
최종 업데이트: 2025-07-27(UTC)
[null,null,["최종 업데이트: 2025-07-27(UTC)"],[],[],null,["# Android Rust introduction\n\nThe Android platform provides support for developing native OS components in Rust,\na modern systems-programming language that provides memory safety guarantees with\nperformance equivalent to C/C++. Rust uses a combination of compile-time checks\nthat enforce object lifetime and ownership, and runtime checks that ensure valid\nmemory accesses, thereby eliminating the need for a garbage collector.\n\nRust provides a range of modern language features which allow developers to be\nmore productive and confident in their code:\n\n- **Safe concurrent programming** - The ease with which this allows users to write efficient, thread-safe code has given rise to Rust's [Fearless Concurrency](https://doc.rust-lang.org/book/ch16-00-concurrency.html) slogan.\n- **Expressive type system** - Rust helps prevent logical programming bugs by allowing for highly expressive types (such as Newtype wrappers, and enum variants with contents).\n- **Stronger Compile-time Checks** - More bugs caught at compile-time increases developer confidence that when code compiles successfully, it works as intended.\n- **Built-in Testing Framework** - Rust provides a built-in testing framework where unit tests can be placed alongside the implementation they test, making unit testing easier to include.\n- **Error handling enforcement** - Functions with recoverable failures can return a [Result type](https://doc.rust-lang.org/book/ch09-02-recoverable-errors-with-result.html), which will be either a success variant or an error variant. The compiler requires callers to check for and handle the error variant of a `Result` enum returned from a function call. This reduces the potential for bugs resulting from unhandled failures.\n- **Initialization** - Rust requires every variable to be initialized to a legal member of its type before use, preventing an unintentional initialization to an unsafe value.\n- **Safer integer handling** - All integer-type conversions are explicit casts. Developers can't accidentally cast during a function call when assigning to a variable, or when attempting to do arithmetic with other types. Overflow checking is on by default in Android for Rust, which requires overflow operations to be explicit.\n\nFor more information, see the series of blog posts on Android Rust support:\n\n- [Rust in the Android Platform](https://security.googleblog.com/2021/04/rust-in-android-platform.html) \n Provides an overview on why the Android team introduced Rust as a new platform language.\n- [Integrating Rust into the Android Open Source Project](https://security.googleblog.com/2021/05/integrating-rust-into-android-open.html) \n Discusses how Rust support has been introduced to the build system, and why certain design decisions were made.\n- [Rust/C++ interop in the Android Platform](https://security.googleblog.com/2021/06/rustc-interop-in-android-platform.html) \n Discusses the approach to Rust/C++ interoperability within Android."]]