تنظيم صفحاتك في مجموعات
يمكنك حفظ المحتوى وتصنيفه حسب إعداداتك المفضّلة.
ملفات تعريف بدء التشغيل هي مجموعة فرعية من ملفات تعريف المرجع. تستخدم "ملفات تعريف بدء التشغيل" نظام الإنشاء لتحسين الفئات والطرق التي تحتوي عليها من خلال تحسين تصميم الرمز في ملفات DEX الخاصة بحزمة APK. باستخدام "ملفات تعريف بدء التشغيل"،
تكون سرعة بدء تشغيل تطبيقك عادةً أعلى بنسبة تتراوح بين% 15 و% 30 مقارنةً باستخدام "ملفات تعريف Baseline" وحدها.
الشكل 1. تحسين موضع الرمز البرمجي من خلال تحسين تنسيق DEX
المتطلبات
ننصحك باستخدام "ملفات بدء التشغيل" مع الأدوات التالية:
الإصدار 1.2.0 من Jetpack Macrobenchmark أو الإصدارات الأحدث
الإصدار 8.2 من المكوّن الإضافي لنظام Gradle المتوافق مع Android أو إصدار أحدث
الإصدار Iguana من "استوديو Android" أو إصدار أحدث
بالإضافة إلى ذلك، تحتاج إلى الإعدادات التالية في تطبيقك:
تم تفعيل R8. بالنسبة إلى إصدارك، اضبط قيمة isMinifyEnabled = true.
تم تفعيل تحسينات تنسيق DEX. في الحزمة baselineProfile {} ضمن ملف إنشاء وحدة التطبيق، اضبط dexLayoutOptimization = true.
إنشاء ملف شخصي خاص بالشركات الناشئة
ينشئ Android Studio ملف Startup Profile إلى جانب ملف Baseline Profile عند استخدام نموذج Baseline Profile Generator التلقائي.
إنّ الخطوات العامة لإنشاء ملف إعداد وبدء تشغيل هي نفسها الخطوات المتّبعة لإنشاء ملف أساسي.
الطريقة التلقائية لإنشاء ملف بدء التشغيل هي استخدام نموذج وحدة Baseline Profile
Generator من داخل "استوديو Android". ويشمل ذلك التفاعلات عند بدء التشغيل التي تشكّل ملفًا أساسيًا لتجربة بدء التشغيل. لتعزيز ملف تعريف التطبيق الناشئ هذا باستخدام المزيد من رحلات المستخدمين المهمة (CUJ)، أضِف رحلات المستخدمين المهمة عند بدء تشغيل تطبيقك إلى حظر rule مع ضبط includeInStartupProfile على true. بالنسبة إلى التطبيقات البسيطة، قد يكون تشغيل MainActivity للتطبيق كافيًا. بالنسبة إلى التطبيقات الأكثر تعقيدًا، ننصحك بإضافة نقاط الدخول الأكثر شيوعًا إلى تطبيقك، مثل بدء تشغيل التطبيق من الشاشة الرئيسية أو الانتقال إلى رابط لصفحة معيّنة.
تعرض مقتطفات الرموز البرمجية التالية أداة إنشاء ملفات Baseline Profile (الملف BaselineProfileGenerator.kt تلقائيًا) التي تتضمّن بدء تشغيل تطبيقك من الشاشة الرئيسية وفتح رابط لصفحة في التطبيق. ينقل الرابط المؤدي إلى صفحة في التطبيق المستخدم مباشرةً إلى خلاصة الأخبار في التطبيق، وليس إلى الشاشة الرئيسية للتطبيق.
@RunWith(AndroidJUnit4::class)@LargeTestclassBaselineProfileGenerator{@get:Rulevalrule=BaselineProfileRule()@Testfungenerate(){rule.collect(packageName="com.example.app",includeInStartupProfile=true){// Launch directly into the NEWS_FEED.startActivityAndWait(Intent().apply{setPackage(packageName)setAction("com.example.app.NEWS_FEED")})}}}
نفِّذ عملية الإعداد إنشاء ملف تعريف أساسي للتطبيق وابحث عن قواعد ملف تعريف بدء التشغيل في src/<variant>/generated/baselineProfiles/startup-prof.txt.
اعتبارات عند إنشاء ملفات شخصية للشركات الناشئة
إذا لم يكن ذلك ممكنًا، سيتجاوز رمز بدء التشغيل ملفات DEX التالية،
التي يتم ملؤها بعد ذلك بفئات وطرق أخرى.
راجِع مقالة تأكيد تحسين ملفات تعريف بدء التشغيل لمعرفة ما إذا كان ذلك يحدث، والإجراءات التي يمكنك اتّخاذها لتقليل حجم بدء تشغيل تطبيقك وتسريعه.
لتحديد رحلات المستخدمين التي يجب تغطيتها عند إنشاء ملف شخصي لشركة ناشئة، ضع في اعتبارك المكان الذي يبدأ فيه معظم المستخدمين استخدام التطبيق. ويحدث ذلك عادةً من مشغّل التطبيقات وبعد تسجيل الدخول. وهذه هي أيضًا أبسط رحلة للملف الشخصي الأساسي.
بعد تغطية حالة الاستخدام الأولى، اتّبِع مسار الإحالة الناجحة للمستخدم عند بدء تشغيل التطبيق. في كثير من الحالات، تتّبع مسارات إحالة بدء تشغيل التطبيق القائمة التالية:
نشاط المشغّل الرئيسي
الإشعارات التي تؤدي إلى بدء تشغيل التطبيق
أنشطة المشغّل الاختيارية
يمكنك العمل على هذه القائمة من الأعلى والتوقّف قبل أن يصبح الملف classes.dex ممتلئًا. لتغطية المزيد من رحلات المستخدمين بعد ذلك، يمكنك نقل الرمز البرمجي خارج مسار بدء التشغيل وإضافة المزيد من رحلات المستخدمين.
لنقل الرمز البرمجي خارج مسار بدء التشغيل، افحص بيانات تتبُّع Perfetto أثناء بدء تشغيل التطبيق وابحث عن العمليات التي تستغرق وقتًا طويلاً. يمكنك أيضًا استخدام Macrobenchmark
مع تفعيل تتبُّع الدوال البرمجية
للحصول على عرض كامل وقابل للتشغيل التلقائي لعمليات استدعاء الدوال البرمجية أثناء بدء تشغيل التطبيق.
أفلام مُقترَحة لك
ملاحظة: يتم عرض نص الرابط عندما تكون JavaScript غير مفعّلة
يخضع كل من المحتوى وعيّنات التعليمات البرمجية في هذه الصفحة للتراخيص الموضحّة في ترخيص استخدام المحتوى. إنّ Java وOpenJDK هما علامتان تجاريتان مسجَّلتان لشركة Oracle و/أو الشركات التابعة لها.
تاريخ التعديل الأخير: 2025-07-27 (حسب التوقيت العالمي المتفَّق عليه)
[[["يسهُل فهم المحتوى.","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-07-27 (حسب التوقيت العالمي المتفَّق عليه)"],[],[],null,["# Create Startup Profiles\n\nStartup Profiles are a subset of Baseline Profiles. Startup Profiles are used\nby the build system to further optimize the classes and methods they contain\nby improving the layout of code in your APK's DEX files. With Startup Profiles,\nyour app startup is usually between 15% and 30% faster than with Baseline\nProfiles alone.\n| **Note:** Startup Profiles impact your app's APK size, and the performance impact they provide might be large or small depending on how your app is structured. We recommend running an A/B test to assess the effect of Startup Profiles on your app.\n**Figure 1.** Code locality improvement from DEX layout optimization.\n\nRequirements\n------------\n\nWe recommend using Startup Profiles with the following tools:\n\n- Jetpack Macrobenchmark 1.2.0 or higher\n- Android Gradle Plugin 8.2 or higher\n- Android Studio Iguana or higher\n\nIn addition, you need the following settings in your app:\n\n- [R8](/build/shrink-code) enabled. For your release build, set `isMinifyEnabled = true`.\n- DEX layout optimizations enabled. In the `baselineProfile {}` block of the app module's build file, set `dexLayoutOptimization = true`.\n\nCreate a Startup Profile\n------------------------\n\n| **Note:** Unlike regular Baseline Profiles, Startup Profiles can't be contributed by libraries; Startup Profiles only include rules generated by the startup tests that you define, so make sure that you include all the main ways that users can enter your app.\n| **Note:** AGP 8.2 doesn't support distinct Startup Profiles per variant. If you're using AGP 8.2, use Baseline Profile Gradle plugin 1.2.3 or higher to automatically merge across variants. Upgrade to AGP 8.3 to use distinct Startup Profiles per variant.\n\nAndroid Studio creates a Startup Profile alongside a Baseline Profile when you\nuse the default Baseline Profile Generator template.\n\nThe general steps to create and generate a Startup Profile are the same as those\nto [create a Baseline Profile](/topic/performance/baselineprofiles/create-baselineprofile).\n\nThe default way to create a Startup Profile is by using the Baseline Profile\nGenerator module template from within Android Studio. This includes startup\ninteractions that form a basic Startup Profile. To augment this Startup Profile\nwith more Critical User Journeys (CUJs), add your app startup CUJs to a `rule`\nblock with `includeInStartupProfile` set to `true`. For simple apps, launching\nthe app's `MainActivity` might be sufficient. For more complex apps, consider\nadding the most common entry points into your app, such as starting the app from\nthe home screen or launching into a [deep link](/training/app-links/deep-linking).\n\nThe following code snippet shows a Baseline Profile generator (by default the\n`BaselineProfileGenerator.kt` file) that includes starting your app from the\nhome screen and launching into a deep link. The deep link goes directly to the\napp's news feed, not the app's home screen. \n\n @RunWith(AndroidJUnit4::class)\n @LargeTest\n class BaselineProfileGenerator {\n\n @get:Rule\n val rule = BaselineProfileRule()\n\n @Test\n fun generate() {\n rule.collect(\n packageName = \"com.example.app\",\n includeInStartupProfile = true\n ) {\n // Launch directly into the NEWS_FEED.\n startActivityAndWait(Intent().apply {\n setPackage(packageName)\n setAction(\"com.example.app.NEWS_FEED\")\n })\n }\n }\n }\n\nRun the [**Generate Baseline Profile for app** configuration](/topic/performance/baselineprofiles/create-baselineprofile#generate-profile) and find the\nStartup Profile rules at\n`src/\u003cvariant\u003e/generated/baselineProfiles/startup-prof.txt`.\n\nConsiderations to creating startup profiles\n-------------------------------------------\n\n| **Tip:** For the most performance improvement, try to limit the user journeys added to your startup profile so that you stay within one DEX file.\n| **Note:** To get the highest impact performance improvement from startup profile, the startup code should fit into the `classes.dex` file, which is the first DEX file. If that's not possible, the startup code will overflow into the next DEX files, which are then filled up with other classes and methods. See [Confirm Startup Profiles optimization](/topic/performance/baselineprofiles/confirm-startup-profiles) to find out if this happens, and what you can do to reduce your app's startup size to make it start faster.\n\nTo decide which user journeys to cover when creating a startup profile, consider\nwhere most users start the application. Usually that is from the launcher and\nafter they have been logged in. This is also the most basic baseline profile\njourney.\n\nAfter the first use case has been covered, follow the user funnel for app\nstartup. In many cases, app startup funnels follow this list:\n\n1. Main launcher activity\n2. Notifications that trigger app startup\n3. Optional launcher activities\n\nWork this list from the top and stop before classes.dex is full. To cover\nmore journeys afterwards, move code out of the startup path and add more\njourneys.\nTo move code out of the startup path, inspect Perfetto traces during app startup\nand look for long running operations. You can also use a [macrobenchmark](/topic/performance/benchmarking/macrobenchmark-overview)\nwith [method tracing enabled](/topic/performance/benchmarking/macrobenchmark-instrumentation-args#profiling-mode)\nfor an automatable and complete view of method calls during app startup.\n\nRecommended for you\n-------------------\n\n- Note: link text is displayed when JavaScript is off\n- [Create Baseline Profiles {:#creating-profile-rules}](/topic/performance/baselineprofiles/create-baselineprofile)\n- [Baseline Profiles {:#baseline-profiles}](/topic/performance/baselineprofiles/overview)\n- [Writing a Microbenchmark](/topic/performance/benchmarking/microbenchmark-write)"]]