تنظيم صفحاتك في مجموعات
يمكنك حفظ المحتوى وتصنيفه حسب إعداداتك المفضّلة.
توفّر الوحدات حاوية لرمز مصدر التطبيق
وملفات الموارد والإعدادات على مستوى التطبيق، مثل
ملف الإصدار على مستوى الوحدة وملف بيان Android.
يمكن إنشاء كل وحدة واختبارها وتصحيح الأخطاء بشكل مستقل.
يستخدم "استوديو Android" وحدات لتسهيل إضافة أجهزة جديدة إلى مشروعك. من خلال اتباع بعض الخطوات البسيطة في Android Studio، يمكنك إنشاء وحدة
تتضمن تعليمات برمجية مخصصة لنوع الجهاز،
مثل Wear OS أو Android TV. ينشئ استوديو Android تلقائيًا
أدلة الوحدات، مثل أدلة المصدر والموارد،
وملف build.gradle تلقائي مناسبًا لنوع الجهاز.
وينشئ أيضًا Android Studio وحدات للأجهزة مع تكوينات التصميم الموصى بها، مثل استخدام مكتبة Leanback لوحدات Android TV.
توضح هذه الصفحة كيفية إضافة وحدة جديدة لجهاز محدد.
ويسهل Android Studio أيضًا إضافة مكتبة أو
وحدة في Google Cloud إلى مشروعك. للحصول على تفاصيل حول إنشاء وحدة مكتبة، راجِع القسم إنشاء وحدة مكتبة.
إنشاء وحدة جديدة
لإضافة وحدة جديدة إلى مشروعك لجهاز جديد، يمكنك المتابعة على النحو التالي:
انقر على ملف > جديد > وحدة جديدة.
في النافذة إنشاء وحدة جديدة التي تظهر، يوفّر "استوديو Android"
وحدات الأجهزة التالية:
وحدة هاتف وجهاز لوحي
وحدة Wear OS
وحدة Android TV
وحدة زجاجية
اختَر الوحدة التي تريدها للجهاز، ثم انقر على التالي.
في نموذج ضبط الوحدة الجديدة، أدخِل التفاصيل التالية:
اسم التطبيق: يتم استخدام هذا الاسم كعنوان
لرمز مشغّل التطبيقات للوحدة الجديدة.
اسم الوحدة: يُستخدم هذا النص كاسم للمجلد الذي يظهر فيه رمز المصدر وملفات الموارد.
اسم الحزمة: هذه هي مساحة اسم Java للرمز البرمجي في الوحدة. تتم إضافتها كسمة package في ملف بيان Android الخاص بالوحدة.
الحد الأدنى من حزمة SDK:
يشير هذا الإعداد إلى أدنى إصدار من نظام Android الأساسي يتوافق مع وحدة التطبيق. تحدّد هذه القيمة السمة minSdkVersion في ملف build.gradle، ويمكنك تعديله لاحقًا.
وبعد ذلك، انقر على التالي.
بناءً على وحدة الجهاز التي حددتها، تعرض الصفحة التالية مجموعة من نماذج الرموز المناسبة التي يمكنك اختيارها لاستخدامها كنشاطك الرئيسي. انقر على نموذج النشاط الذي تريد البدء به،
ثم انقر على التالي. إذا كنت لا تحتاج إلى نشاط، انقر على
إضافة ليس هناك نشاط، وانقر على إنهاء، وعندها تكون قد انتهيت.
إذا اخترت نموذج نشاط، أدخِل إعدادات نشاطك في صفحة تخصيص
النشاط. تطلب معظم النماذج اسم النشاط واسم
التنسيق والعنوان ولغة المصدر، لكن يحتوي كل نموذج على إعدادات متعلقة بالنشاط. انقر على
إنهاء. عند إنشاء وحدة تطبيق باستخدام نموذج نشاط، يمكنك تشغيل الوحدة واختبارها على جهازك فورًا.
ينشئ استوديو Android جميع الملفات اللازمة للوحدة الجديدة ويزامن
المشروع مع ملفات درجات الوحدة الجديدة. تؤدي إضافة وحدة لجهاز جديد أيضًا إلى إضافة أي تبعيات مطلوبة للجهاز المستهدف إلى ملف إصدار الوحدة.
بعد اكتمال مزامنة مشروع Gradle، ستظهر الوحدة الجديدة في نافذة المشروع على اليمين. إذا لم يظهر لك مجلد الوحدة الجديد،
تأكَّد من أنّ النافذة تعرض طريقة عرض Android.
استيراد وحدة
لاستيراد وحدة حالية إلى مشروعك، اتّبِع الخطوات التالية:
انقر على ملف > جديد > استيراد وحدة.
في المربّع دليل المصدر، اكتب أو اختَر دليل الوحدات
التي تريد استيرادها:
في حال استيراد وحدة نمطية واحدة، عليك الإشارة إلى دليلها الجذري.
في حال استيراد وحدات متعدّدة من مشروع، يُرجى الإشارة إلى
مجلد المشروع. بالنسبة إلى كل وحدة داخل المجلد، يظهر مربّع يشير إلى
موقع المصدر واسم الوحدة. تأكَّد من وضع علامة في المربّع
استيراد لكل وحدة تريد استيرادها.
إذا كانت وحداتك تتضمّن تبعيات أخرى، سيتم إدراجها ضمن
الوحدات الإضافية المطلوبة.
اكتب أسماء الوحدات المطلوبة في حقول أسماء الوحدة.
انقر على إنهاء.
بعد استيراد الوحدة، ستظهر في نافذة المشروع
على يمين الصفحة.
الخطوات التالية
بعد إضافة وحدة جديدة، يمكنك تعديل رمز الوحدة والموارد،
وضبط إعدادات إنشاء الوحدة، وإنشاء الوحدة. يمكنك أيضًا تشغيل الوحدة وتصحيح أخطائها
مثل أي تطبيق آخر.
يجب أيضًا إضافة رموز برمجية وموارد متوافقة مع الجهاز الجديد بشكل صحيح. لمزيد من المعلومات حول كيفية تطوير وحدات تطبيقات لأنواع الأجهزة المختلفة، يُرجى الاطّلاع على الوثائق المناسبة:
أثناء تطوير الوحدة الجديدة، يمكنك إنشاء رمز مستقل للجهاز تم تكراره في وحدة تطبيق مختلفة. وبدلاً من الاحتفاظ بالتعليمات البرمجية المكررة، يمكنك نقل التعليمة البرمجية
التي تمت مشاركتها إلى وحدة مكتبة وإضافة المكتبة كتبعية إلى وحدات التطبيق.
للحصول على مزيد من المعلومات حول إنشاء وحدة مكتبة وإضافتها كوحدة تابعة، يُرجى الاطّلاع على
إنشاء مكتبة Android.
يخضع كل من المحتوى وعيّنات التعليمات البرمجية في هذه الصفحة للتراخيص الموضحّة في ترخيص استخدام المحتوى. إنّ Java وOpenJDK هما علامتان تجاريتان مسجَّلتان لشركة Oracle و/أو الشركات التابعة لها.
تاريخ التعديل الأخير: 2023-09-25 (حسب التوقيت العالمي المتفَّق عليه)
[[["يسهُل فهم المحتوى.","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"]],["تاريخ التعديل الأخير: 2023-09-25 (حسب التوقيت العالمي المتفَّق عليه)"],[],[],null,["# Add a module for a new device\n\nModules provide a container for your app's\nsource code, resource files, and app level settings, such as the\nmodule-level build file and Android manifest file.\nEach module can be independently built, tested, and debugged.\n\nAndroid Studio uses modules to make it easy to add new devices to\nyour project. By following a few simple steps in Android Studio,\nyou can create a module to contain code that's specific to a device type,\nsuch as Wear OS or Android TV. Android Studio automatically\ncreates module directories, such as source and resource directories, and\na default `build.gradle` file appropriate for the device type.\nAlso, Android Studio creates device modules with recommended build configurations,\nsuch as using the Leanback library for Android TV modules.\n\nThis page describes how to add a new module for a specific device.\n\nAndroid Studio also makes it easy to add a library or\nGoogle Cloud module to your project. For details on creating a library module,\nsee [Create a\nLibrary Module](/studio/projects/android-library#CreateLibrary).\n\n\nCreate a new module\n-------------------\n\nTo add a new module to your project for a new device, proceed as follows:\n\n1. Click **File** \\\u003e **New** \\\u003e **New Module**.\n2. In the **Create New Module** window that appears, Android Studio offers the following device modules:\n - Phone \\& Tablet Module\n - Wear OS Module\n - Android TV Module\n - Glass Module\n\n Select the module for the device you want, and then click **Next**.\n3. In the **Configure your new module** form, enter the following details:\n - **Application Name**: This name is used as the title of your app launcher icon for the new module.\n - **Module Name**: This text is used as the name of the folder where your source code and resources files are visible.\n - **Package Name** : This is the Java namespace for the code in your module. It is added as the [`package`](/guide/topics/manifest/manifest-element#package) attribute in the module's [Android manifest file](/guide/topics/manifest/manifest-intro). **Important:** Module package names must be globally unique. You can't have two modules with the same package name in the same project.\n - **Minimum SDK** : This setting indicates the lowest version of the Android platform that the app module supports. This value sets the `minSdkVersion` attribute in the `build.gradle` file, which you can edit later.\n\n Then click **Next**.\n4. Depending on which device module you selected, the following page displays a selection of appropriate code templates you can select to use as your main activity. Click an activity template with which you want to start, and then click **Next** . If you don't need an activity, click **Add No Activity** , click **Finish**, and then you're done.\n5. If you chose an activity template, enter the settings for your activity on the **Customize\n the Activity** page. Most templates ask for an **Activity Name** , **Layout\n Name** , **Title** , and **Source Language** , but each template has activity-specific settings. Click **Finish**. When you create an app module with an activity template, you can immediately run and test the module on your device.\n\nAndroid Studio creates all the necessary files for the new module and\nsyncs the project with the new module gradle files. Adding a module\nfor a new device also adds any required dependencies for the target\ndevice to the module's build file.\n\nOnce the Gradle project sync completes, the new module appears in\nthe **Project** window on the left. If you don't see the new module\nfolder, make sure the window is displaying the [Android view](/studio/projects#ProjectFiles).\n\nImport a module\n---------------\n\nTo import an existing module into your project, proceed as follows:\n\n1. Click **File \\\u003e New \\\u003e Import Module**.\n2. In the **Source directory** box, type or select the directory of the module(s) that you want to import:\n - If you are importing one module, indicate its root directory.\n - If you are importing multiple modules from a project, indicate the project folder. For each module inside the folder, a box appears and indicates the **Source location** and **Module name** . Make sure the **Import** box is checked for each module that you want to import.\n\n If your module(s) have other dependencies, they will be listed to import under **Additional required modules**.\n3. Type your desired module name(s) in the **Module name** field(s).\n4. Click **Finish.**\n\nOnce the module is imported, it appears in the [**Project** window](https://developer.android.com/studio/projects/index.html#ProjectFiles) on the left.\n\nNext steps\n----------\n\nOnce you've added a new module, you can modify the module code and resources,\nconfigure module build settings, and build the module. You can also run and debug\nthe module like any other app.\n\n- To learn about build settings for a module, see [The Module-level Build File](/studio/build#module-level).\n- To build and run a specific module, see [Select and build a different module](/studio/run#build-module).\n\nYou'll also want to add code and resources to properly support the new\ndevice. For more information about how to develop app modules for different\ndevice types, see the corresponding documentation:\n\n- For Wear OS modules: [Creating and Running a Wearable App](https://developer.android.com/training/wearables/apps/creating.html)\n- For Android TV modules: [Get Started with TV Apps](https://developer.android.com/training/tv/start/start.html)\n- For Glass modules: [GDK Quick Start](https://developers.google.com/glass/develop/gdk/quick-start#for_android_experts)\n\nAs you develop your new module, you might create device independent code that is already\nduplicated in a different app module. Instead of maintaining duplicate code, consider moving\nthe shared code to a library module and adding the library as a dependency to your app modules.\nFor more information on creating a library module and adding it as a dependency, see\n[Create an Android Library](/studio/projects/android-library)."]]