קל לארגן דפים בעזרת אוספים
אפשר לשמור ולסווג תוכן על סמך ההעדפות שלך.
סקירה כללית
Rust היא שפת תכנות מודרנית למערכות שמתמקדת בביצועים ובבטיחות, במיוחד בבטיחות הזיכרון. השימוש ב-Rust הופך לחשוב יותר ויותר במערכת האקולוגית של Android כחלופה בטוחה יותר ל-C/C++ לפיתוח רכיבי מערכת קריטיים, והוא מציע אבטחה ויציבות משופרות.
בדף הזה מוסבר איך להגדיר את Android Studio for Platform (ASfP) כדי לתמוך בפיתוח Rust בפרויקטים של Android Open Source Project (AOSP).
דרישות מוקדמות
ASfP Installed: מוודאים ש-ASfP מותקן ופועל.
תשלום בפלטפורמה: צריך תשלום פעיל בפלטפורמת AOSP במחשב.
הפעלת תמיכה ב-Rust
כך מגדירים תמיכה ב-Rust בפרויקט ASfP:
הפעלת Rust
כשיוצרים פרויקט חדש באשף ההגדרה, פשוט מסמנים את התיבה של Rust:
תיבת הסימון Rust באשף ההגדרה של פרויקט חדש.
בפרויקטים קיימים, עוברים להגדרה .asfp-project ומוסיפים את rust ל-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>
סנכרון הפרויקט:
אחרי שמבצעים את השלבים הקודמים, צריך להפעיל סנכרון של הפרויקט כדי לוודא שכל השינויים יחולו וסביבת הפיתוח המשולבת (IDE) תזהה את פרויקט Rust: עוברים אל File > Sync Project (קובץ > סנכרון הפרויקט).
אימות ההצלחה
אחרי שמבצעים את השלבים האלה:
הסמל rust-project.json אמור להופיע בתצוגת הפרויקט (בקטע המקור iml). הקובץ הזה נוצר על ידי Soong במהלך הניתוח ומקושר באמצעות קישור סמלי אל ספריית הבסיס של repo, שנדרשת כדי ש-LSP יוכל לספק שירותי שפה. אל תערכו את הקובץ הזה ישירות. במקום זאת, סנכרנו מחדש כדי ש-Soong יטפל בו.
חשוב לוודא שהתג rust מופיע בקטע other_languages בהגדרות של .asfp-project.
מוודאים שאסימון rust-project.json נוצר.
תכונות ספציפיות ל-Rust (שמתוארות ומוצגות בהמשך) אמורות להיות מופעלות בסביבת הפיתוח המשולבת (IDE).
תכונות עיקריות של סביבות פיתוח משולבות (IDE) ב-Rust
השלמת קוד: קבלת הצעות חכמות לקוד Rust, כולל פריטים ממודולים אחרים.
השלמת קוד שמציעה פריטים ממודול Rust אחר.
ניווט: מעבר מהיר להגדרות וחיפוש של שימושים בסמלי Rust בפרויקט.
ניווט להגדרה של סמל Rust.חיפוש כל המקומות שבהם נעשה שימוש בסמל Rust.
הסברים קצרים: מעבירים את העכבר מעל סמלים כדי לראות מידע על הסוג ותיעוד.
הסבר קצר שמופיע כשמעבירים את העכבר מעל סמל של Rust ממודול אחר, ובו מידע על הסוג.
הצעות מוצגות: אפשר לראות מידע על הסוגים ורמזים הקשריים אחרים ישירות בעורך.
רמזים מוטמעים שמציגים מידע על סוג בתוך הקוד.
תצוגת מבנה: אפשר לנווט במבנה של קובצי Rust באמצעות חלון הכלים Structure (מבנה) (View > Tool Windows > Structure (תצוגה > חלונות כלים > מבנה)).
חלון הכלים של המבנה שבו מוצג המתאר של קובץ Rust.
Refactoring: שינוי שם של סמלים בצורה בטוחה ועדכון כל השימושים.
שינוי השם של סמל Rust ועדכון כל ההפניות אליו.
ניתוח בזמן אמת: קבלת משוב מיידי על שגיאות ואזהרות בקוד Rust.
סביבת פיתוח משולבת (IDE) שמציגה שגיאות ואזהרות בזמן אמת בקוד Rust.
דוגמאות התוכן והקוד שבדף הזה כפופות לרישיונות המפורטים בקטע רישיון לתוכן. Java ו-OpenJDK הם סימנים מסחריים או סימנים מסחריים רשומים של חברת Oracle ו/או של השותפים העצמאיים שלה.
עדכון אחרון: 2025-09-05 (שעון UTC).
[[["התוכן קל להבנה","easyToUnderstand","thumb-up"],["התוכן עזר לי לפתור בעיה","solvedMyProblem","thumb-up"],["סיבה אחרת","otherUp","thumb-up"]],[["חסרים לי מידע או פרטים","missingTheInformationINeed","thumb-down"],["התוכן מורכב מדי או עם יותר מדי שלבים","tooComplicatedTooManySteps","thumb-down"],["התוכן לא עדכני","outOfDate","thumb-down"],["בעיה בתרגום","translationIssue","thumb-down"],["בעיה בדוגמאות/בקוד","samplesCodeIssue","thumb-down"],["סיבה אחרת","otherDown","thumb-down"]],["עדכון אחרון: 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"]]