Zadbaj o dobrą organizację dzięki kolekcji
Zapisuj i kategoryzuj treści zgodnie ze swoimi preferencjami.
Omówienie
Rust to nowoczesny język programowania systemowego, który koncentruje się na wydajności i bezpieczeństwie, zwłaszcza bezpieczeństwie pamięci. Rust odgrywa coraz większą rolę w ekosystemie Androida jako bezpieczniejsza alternatywa dla C/C++ w przypadku tworzenia kluczowych komponentów systemu, zapewniająca większe bezpieczeństwo i stabilność.
Na tej stronie znajdziesz instrukcje konfigurowania Android Studio for Platform (ASfP) w celu obsługi tworzenia kodu w języku Rust w projektach Android Open Source Project (AOSP).
Wymagania wstępne
Zainstalowano ASfP: sprawdź, czy ASfP jest zainstalowany i działa.
Płatność na platformie: na komputerze musisz mieć działającą płatność na platformie AOSP.
Włączanie obsługi języka Rust
Oto instrukcja krok po kroku, jak włączyć obsługę Rusta w projekcie ASfP:
Włącz Rust
Podczas tworzenia nowego projektu w kreatorze konfiguracji po prostu zaznacz pole Rust:
Pole wyboru Rust w kreatorze konfiguracji nowego projektu.
W przypadku istniejących projektów otwórz konfigurację .asfp-project i dodaj rust do 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>
Synchronizacja projektu:
Po wykonaniu powyższych czynności musisz wywołać synchronizację projektu, aby upewnić się, że wszystkie zmiany zostały zastosowane, a IDE rozpoznaje projekt Rust: kliknij File > Sync Project (Plik > Synchronizuj projekt).
Sprawdzanie powodzenia
Po wykonaniu tych czynności:
W widoku projektu (w sekcji źródłowej iml) powinien pojawić się tekst rust-project.json. Ten plik jest generowany przez Soong podczas analizy i łączony symbolicznie z głównym katalogiem repozytorium, co jest niezbędne, aby LSP mogło świadczyć usługi językowe. NIE edytuj tego pliku bezpośrednio. Zamiast tego ponownie zsynchronizuj go, aby Soong mógł go obsłużyć.
Przypominamy, że w konfiguracji .asfp-project w sekcji other_languages
musi być wpisany adres rust.
Sprawdź, czy został wygenerowany element rust-project.json.
W IDE powinny być włączone funkcje specyficzne dla języka Rust (opisane i pokazane poniżej).
Najważniejsze funkcje IDE Rust
Uzupełnianie kodu: otrzymuj inteligentne sugestie dotyczące kodu w języku Rust, w tym elementy z innych modułów.
Autouzupełnianie kodu z sugestiami elementów z innego modułu Rust.
Nawigacja: szybko przechodź do definicji i znajduj użycia symboli języka Rust w projekcie.
Przechodzenie do definicji symbolu w języku Rust.Znajdowanie wszystkich zastosowań symbolu Rust.
Etykietki: najeżdżaj kursorem na symbole, aby wyświetlić informacje o typie i dokumentację.
Etykietka z informacjami o typie symbolu Rust z innego modułu.
Wskazówki wstawiane: wyświetlaj informacje o typie i inne wskazówki kontekstowe bezpośrednio w edytorze.
Wskazówki wstawiane, które wyświetlają informacje o typie w kodzie.
Widok struktury: przeglądaj strukturę plików Rust za pomocą okna narzędziowego Struktura (Widok > Okna narzędziowe > Struktura).
Okno narzędziowe struktury z konspektem pliku Rust.
Refaktoryzacja: bezpieczne zmienianie nazw symboli i aktualizowanie wszystkich miejsc ich użycia.
Zmiana nazwy symbolu Rust i aktualizacja wszystkich jego odwołań.
Analiza w czasie rzeczywistym: otrzymuj natychmiastowe informacje o błędach i ostrzeżeniach w kodzie Rust.
IDE showing real-time errors and warnings in Rust code.
Treść strony i umieszczone na niej fragmenty kodu podlegają licencjom opisanym w Licencji na treści. Java i OpenJDK są znakami towarowymi lub zastrzeżonymi znakami towarowymi należącymi do firmy Oracle lub jej podmiotów stowarzyszonych.
Ostatnia aktualizacja: 2025-09-05 UTC.
[[["Łatwo zrozumieć","easyToUnderstand","thumb-up"],["Rozwiązało to mój problem","solvedMyProblem","thumb-up"],["Inne","otherUp","thumb-up"]],[["Brak potrzebnych mi informacji","missingTheInformationINeed","thumb-down"],["Zbyt skomplikowane / zbyt wiele czynności do wykonania","tooComplicatedTooManySteps","thumb-down"],["Nieaktualne treści","outOfDate","thumb-down"],["Problem z tłumaczeniem","translationIssue","thumb-down"],["Problem z przykładami/kodem","samplesCodeIssue","thumb-down"],["Inne","otherDown","thumb-down"]],["Ostatnia aktualizacja: 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"]]