Kể từ ngày 27 tháng 3 năm 2025, bạn nên sử dụng android-latest-release
thay vì aosp-main
để xây dựng và đóng góp cho AOSP. Để biết thêm thông tin, hãy xem phần Thay đổi đối với AOSP.
Thiết lập Rust IDE
Sử dụng bộ sưu tập để sắp xếp ngăn nắp các trang
Lưu và phân loại nội dung dựa trên lựa chọn ưu tiên của bạn.
Tính năng hỗ trợ IDE cho Rust trong Android dựa trên rust-analyzer.
rust-analyzer
là một giao thức máy chủ ngôn ngữ mà IDE của bạn sử dụng để hiểu cấu trúc mã và cung cấp các tính năng như hoàn thành mã hoặc chuyển đến định nghĩa. Trước khi bắt đầu, hãy tìm tài liệu Bắt đầu nhanh với rust-analyzer để biết cách định cấu hình IDE hoặc trình chỉnh sửa để sử dụng giao thức rust-analyzer
.
Android cung cấp cấu hình cho phép rust-analyzer
hiểu cách xây dựng các mô-đun Android Rust. Điều này được mô tả trong tệp rust-project.json
do Soong tạo. Đối với một số IDE như Visual Studio Code, tệp này được aidegen
tạo bằng cách sử dụng các đối số tuỳ chọn -l r
(để chọn Rust làm ngôn ngữ). Nếu bạn sử dụng một IDE khác, hãy tạo tệp rust-project.json
theo cách thủ công bằng mã sau:
// Generates rust-project.json in out/soong/
SOONG_GEN_RUST_PROJECT=1 m nothing
// Creates a symbolic link
ln -s $ANDROID_BUILD_TOP/out/soong/rust-project.json $ANDROID_BUILD_TOP
Bạn có thể sử dụng phiên bản rust-analyzer
ổn định, tạo sẵn trong cây tại prebuilts/rust/linux-x86/stable/rust-analyzer.
Nội dung và mã mẫu trên trang này phải tuân thủ các giấy phép như mô tả trong phần Giấy phép nội dung. Java và OpenJDK là nhãn hiệu hoặc nhãn hiệu đã đăng ký của Oracle và/hoặc đơn vị liên kết của Oracle.
Cập nhật lần gần đây nhất: 2025-07-27 UTC.
[[["Dễ hiểu","easyToUnderstand","thumb-up"],["Giúp tôi giải quyết được vấn đề","solvedMyProblem","thumb-up"],["Khác","otherUp","thumb-up"]],[["Thiếu thông tin tôi cần","missingTheInformationINeed","thumb-down"],["Quá phức tạp/quá nhiều bước","tooComplicatedTooManySteps","thumb-down"],["Đã lỗi thời","outOfDate","thumb-down"],["Vấn đề về bản dịch","translationIssue","thumb-down"],["Vấn đề về mẫu/mã","samplesCodeIssue","thumb-down"],["Khác","otherDown","thumb-down"]],["Cập nhật lần gần đây nhất: 2025-07-27 UTC."],[],[],null,["# Rust IDE setup\n\nThe IDE support for Rust in Android relies on [rust-analyzer](https://rust-analyzer.github.io/).\n`rust-analyzer` is a [language server protocol](https://microsoft.github.io/language-server-protocol/)\nused by your IDE to understand the code structure and to provide features\nsuch as code completion or jump-to definition. Before you start, search the\n[rust-analyzer QuickStart](https://rust-analyzer.github.io/) documentation for how to configure your\nIDE or editor to use the `rust-analyzer` protocol.\n\nAndroid provides the configuration that enables `rust-analyzer` to understand\nhow Android Rust modules are built. This is described in the Soong-generated file\n`rust-project.json`. For some IDEs such as Visual Studio Code, this file is\ngenerated by [`aidegen`](https://android.googlesource.com/platform/tools/asuite/+/refs/heads/android16-release/aidegen/README.md#2_basic-usage),\nusing the `-l r` option arguments (to select Rust as the language). If you use\na different IDE, manually generate a `rust-project.json` file with the following code: \n\n // Generates rust-project.json in out/soong/\n SOONG_GEN_RUST_PROJECT=1 m nothing\n // Creates a symbolic link\n ln -s $ANDROID_BUILD_TOP/out/soong/rust-project.json $ANDROID_BUILD_TOP\n\nA prebuilt, stable version of `rust-analyzer` is available in-tree at\n[prebuilts/rust/linux-x86/stable/rust-analyzer](https://cs.android.com/android/platform/superproject/+/android-latest-release:prebuilts/rust/linux-x86/stable/rust-analyzer)."]]