Tetap teratur dengan koleksi
Simpan dan kategorikan konten berdasarkan preferensi Anda.
Ringkasan
Rust adalah bahasa pemrograman sistem modern yang berfokus pada performa dan keamanan, terutama keamanan memori. Rust menjadi makin penting dalam ekosistem Android sebagai alternatif yang lebih aman untuk C/C++ dalam mengembangkan komponen sistem penting, sehingga menawarkan keamanan dan stabilitas yang lebih baik.
Halaman ini memandu Anda menyiapkan Android Studio untuk Platform (ASfP) guna mendukung pengembangan Rust dalam project Android Open Source Project (AOSP) Anda.
Prasyarat
ASfP Terinstal: Pastikan Anda telah menginstal dan menjalankan ASfP.
Pembayaran platform: Anda memerlukan pembayaran platform AOSP yang berfungsi di komputer Anda.
Mengaktifkan dukungan Rust
Berikut adalah proses langkah demi langkah untuk membuat dukungan Rust berfungsi di project ASfP Anda:
Aktifkan Rust
Saat membuat project baru di wizard penyiapan, cukup centang kotak untuk Rust:
Kotak centang Rust di wizard penyiapan project baru.
Untuk project yang sudah ada, buka konfigurasi .asfp-project dan tambahkan
rust ke other_languages:
other_languages:-cpp-rust```
<figure>
<img src="/studio/platform/images/1-modify_asfp_project_languages.png" alt="Modifying the .asfp-project file to add rust to other_languages" class="screenshot">
<figcaption>Adding Rust support in the <code>.asfp-project</code> file.</figcaption></figure>
Sinkronkan project Anda:
Setelah melakukan langkah-langkah sebelumnya, Anda perlu memicu sinkronisasi project
untuk memastikan semua perubahan diterapkan dan IDE mengenali project Rust: Buka File > Sync Project.
Memverifikasi keberhasilan
Setelah menyelesaikan langkah-langkah berikut:
Anda akan melihat rust-project.json di tampilan project (di bawah iml sumber). File ini dibuat oleh Soong selama analisis dan ditautkan secara simbolis ke root repo, yang diperlukan agar LSP dapat menyediakan layanan bahasa. JANGAN edit file ini secara langsung; sebagai gantinya, sinkronkan ulang agar Soong menanganinya.
Sebagai pengingat, periksa kembali apakah rust ada di bagian other_languages
dalam konfigurasi .asfp-project Anda.
Pastikan rust-project.json telah dibuat.
Anda akan melihat fitur khusus Rust (dijelaskan dan ditampilkan di bawah) diaktifkan di
IDE Anda.
Fitur utama IDE Rust
Penyelesaian kode: Dapatkan saran cerdas untuk kode Rust, termasuk item dari modul lain.
Penyelesaian kode menyarankan item dari modul Rust yang berbeda.
Navigasi: Beralih dengan cepat ke definisi dan menemukan penggunaan simbol Rust di seluruh project Anda.
Membuka definisi simbol Rust.Menemukan semua penggunaan simbol Rust.
Tooltip: Arahkan kursor ke simbol untuk melihat informasi dan dokumentasi jenis.
Tooltip yang menampilkan informasi jenis untuk simbol Rust dari modul lain.
Petunjuk inlay: Lihat informasi jenis dan petunjuk kontekstual lainnya secara langsung di editor.
Petunjuk sisipan yang menampilkan informasi jenis dalam kode.
Tampilan struktur: Jelajahi struktur file Rust Anda menggunakan jendela alat
Structure (View > Tool Windows > Structure).
Jendela alat struktur yang menampilkan garis batas file Rust.
Refaktorisasi: Mengganti nama simbol dengan aman dan memperbarui semua penggunaannya.
Mengganti nama simbol Rust dan memperbarui semua referensinya.
Analisis real-time: Dapatkan masukan instan tentang error dan peringatan dalam kode Rust Anda.
IDE yang menampilkan error dan peringatan real-time dalam kode Rust.
Konten dan contoh kode di halaman ini tunduk kepada lisensi yang dijelaskan dalam Lisensi Konten. Java dan OpenJDK adalah merek dagang atau merek dagang terdaftar dari Oracle dan/atau afiliasinya.
Terakhir diperbarui pada 2025-09-05 UTC.
[[["Mudah dipahami","easyToUnderstand","thumb-up"],["Memecahkan masalah saya","solvedMyProblem","thumb-up"],["Lainnya","otherUp","thumb-up"]],[["Informasi yang saya butuhkan tidak ada","missingTheInformationINeed","thumb-down"],["Terlalu rumit/langkahnya terlalu banyak","tooComplicatedTooManySteps","thumb-down"],["Sudah usang","outOfDate","thumb-down"],["Masalah terjemahan","translationIssue","thumb-down"],["Masalah kode / contoh","samplesCodeIssue","thumb-down"],["Lainnya","otherDown","thumb-down"]],["Terakhir diperbarui pada 2025-09-05 UTC."],[],[],null,["Overview\n\nRust is a modern systems programming language focused on performance and safety,\nparticularly memory safety. Rust is increasingly important in the Android\necosystem as a safer alternative to C/C++ for developing critical system\ncomponents, offering improved security and stability.\n\nThis page guides you through setting up Android Studio for Platform (ASfP) to\nsupport Rust development within your Android Open Source Project (AOSP)\nprojects.\n\nPrerequisites\n\n- **ASfP Installed:** Verify you have ASfP installed and running.\n- **Platform checkout:** You need a working AOSP platform checkout on your machine.\n\nEnabling Rust support\n\nHere's the step-by-step process to get Rust support working in your ASfP\nproject:\n\n1. **Enable Rust**\n\n - When creating a **new project** in the setup wizard, simply check the box for Rust:\n\n Rust checkbox in new project setup wizard.\n - For existing projects, navigate to your `.asfp-project` config and add `rust` to `other_languages`:\n\n other_languages:\n - cpp\n - rust\n ```\n\n \u003cfigure\u003e\n \u003cimg src=\"/studio/platform/images/1-modify_asfp_project_languages.png\" alt=\"Modifying the .asfp-project file to add rust to other_languages\" class=\"screenshot\"\u003e\n \u003cfigcaption\u003eAdding Rust support in the \u003ccode\u003e.asfp-project\u003c/code\u003e file.\u003c/figcaption\u003e\n \u003c/figure\u003e\n\n\u003c!-- --\u003e\n\n1. **Sync your project:**\n\n - After performing the previous steps, you need to trigger a project sync to ensure that all changes are applied and the IDE recognizes the Rust project: Go to **File \\\u003e Sync Project**.\n\nVerifying success\n\nAfter completing these steps:\n\n- You should see `rust-project.json` in your project view (under the source\n iml). This file is generated by Soong during analysis and symlinked to the\n repo root, which is necessary for LSP to provide language services. **DO\n NOT** edit this file directly; instead, re-sync to let Soong handle it.\n\n As a reminder, double check that `rust` is present under `other_languages`\n in your `.asfp-project` config.\n Ensure that `rust-project.json` has been generated.\n- You should see Rust-specific features (described and shown below) enabled in\n your IDE.\n\nKey Rust IDE features\n\n- **Code completion:** Get intelligent suggestions for Rust code, including\n items from other modules.\n\n Code completion suggesting items from a different Rust module.\n\n \u003cbr /\u003e\n\n- **Navigation:** Quickly jump to definitions and find usages of Rust symbols\n across your project.\n\n Navigating to the definition of a Rust symbol. Finding all usages of a Rust symbol.\n\n \u003cbr /\u003e\n\n- **Tooltips:** Hover over symbols to see type information and documentation.\n\n Tooltip showing type information for a Rust symbol from another module.\n\n \u003cbr /\u003e\n\n- **Inlay hints:** View type information and other contextual hints directly\n in the editor.\n\n Inlay hints showing type information within the code.\n\n \u003cbr /\u003e\n\n- **Structure view:** Navigate the structure of your Rust files using the\n **Structure** tool window (View \\\u003e Tool Windows \\\u003e Structure).\n\n The structure tool window showing the outline of a Rust file.\n\n \u003cbr /\u003e\n\n- **Refactoring:** Safely rename symbols and have all usages updated.\n\n Renaming a Rust symbol and updating all its references.\n\n \u003cbr /\u003e\n\n- **Real-time analysis:** Get instant feedback on errors and warnings in your\n Rust code.\n\n IDE showing real-time errors and warnings in Rust code.\n\n \u003cbr /\u003e"]]