إنشاء ملفات شخصية أساسية لمكتبة
تنظيم صفحاتك في مجموعات
يمكنك حفظ المحتوى وتصنيفه حسب إعداداتك المفضّلة.
لإنشاء ملفات شخصية لمكتبات معيّنة، استخدِم
المكوّن الإضافي لنظام Gradle للملف الشخصي المرجعي
تتضمّن عملية إنشاء الملفات الشخصية المرجعية لمكتبة ما ثلاث وحدات:
- نموذج وحدة تطبيق: يحتوي على نموذج التطبيق الذي يستخدم مكتبتك.
- وحدة المكتبة: الوحدة التي تريد إنشاء الملف الشخصي لها.
- وحدة الملف الشخصي الأساسي: وحدة الاختبار التي تنشئ الملفات الشخصية الأساسية.
لإنشاء ملف شخصي مرجعي لمكتبة، يُرجى اتّباع الخطوات التالية:
- أنشئ وحدة
com.android.test
جديدة، على سبيل المثال،
:baseline-profile
- ضبط الملف
build.gradle.kts
وحدة :baseline-profile
. عملية التهيئة هي
تمامًا مثل التطبيقات، ولكن احرص على تحديد
targetProjectPath
إلى نموذج وحدة التطبيق.
- إنشاء اختبار للملف الشخصي الأساسي في
:baseline-profile
وحدة الاختبار. يجب أن يكون هذا خاصًا بنموذج التطبيق وأن يستخدم جميع
وظائف المكتبة.
- عدِّل الإعدادات في ملف
build.gradle.ktss
في
في المكتبة، لنفترض :library
.
- طبِّق المكوّن الإضافي
androidx.baselineprofile
.
- أضِف تبعية
baselineProfile
إلى السمة
وحدة :baseline-profile
.
- طبِّق الإعداد الذي تريده للمكوّن الإضافي للمستهلك، كما هو موضَّح في
المثال التالي.
Kotlin
plugins {
id("com.android.library")
id("androidx.baselineprofile")
}
android { ... }
dependencies {
...
// Add a baselineProfile dependency to the `:baseline-profile` module.
baselineProfile(project(":baseline-profile"))
}
// Baseline Profile Gradle plugin configuration.
baselineProfile {
// Filters the generated profile rules.
// This example keeps the classes in the `com.library` package all its subpackages.
filter {
include "com.mylibrary.**"
}
}
Groovy
plugins {
id 'com.android.library'
id 'androidx.baselineprofile'
}
android { ... }
dependencies {
...
// Add a baselineProfile dependency to the `:baseline-profile` module.
baselineProfile ':baseline-profile'
}
// Baseline Profile Gradle plugin configuration.
baselineProfile {
// Filters the generated profile rules.
// This example keeps the classes in the `com.library` package all its subpackages.
filter {
include 'com.mylibrary.**'
}
}
- أضِف المكوّن الإضافي
androidx.baselineprofile
إلى
ملف واحد (build.gradle.kts
) في وحدة التطبيق
:sample-app
Kotlin
plugins {
...
id("androidx.baselineprofile")
}
Groovy
plugins {
...
id 'androidx.baselineprofile'
}
- قم بإنشاء الملف الشخصي عن طريق تشغيل الرمز التالي:
./gradlew :library:generateBaselineProfile
في نهاية مهمة الإنشاء، يتم تخزين الملف الشخصي الأساسي في
library/src/main/generated/baselineProfiles
يخضع كل من المحتوى وعيّنات التعليمات البرمجية في هذه الصفحة للتراخيص الموضحّة في ترخيص استخدام المحتوى. إنّ 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 Baseline Profiles for a library\n\nTo create Baseline Profiles for a library, use the\n[Baseline Profile Gradle plugin](/topic/performance/baselineprofiles/configure-baselineprofiles).\n\nThere are three modules involved in creating Baseline Profiles for a library:\n\n- Sample app module: contains the sample app that uses your library.\n- Library module: the module you want to generate the profile for.\n- Baseline Profile module: the test module that generates the Baseline Profiles.\n\nTo generate a Baseline Profile for a library, perform the following steps: \n1. Create a new `com.android.test` module---for example, `:baseline-profile`.\n2. Configure the `build.gradle.kts` file for the `:baseline-profile` module. [The configuration is\n essentially the same as for an app](/topic/performance/baselineprofiles/create-baselineprofile#create-new-profile-plugin), but make sure to set the `targetProjectPath` to the sample app module.\n3. Create a Baseline Profile test in the `:baseline-profile` test module. This needs to be specific to the sample app and must use all the functionalities of the library.\n4. Update the configuration in `build.gradle.ktss` file in the library module, say `:library`.\n 1. Apply the plugin `androidx.baselineprofile`.\n 2. Add a `baselineProfile` dependency to the `:baseline-profile` module.\n3. Apply the consumer plugin configuration you want, as shown in the following example. \n\n### Kotlin\n\n```kotlin\nplugins {\n id(\"com.android.library\")\n id(\"androidx.baselineprofile\")\n}\n\nandroid { ... }\n\ndependencies {\n ...\n // Add a baselineProfile dependency to the `:baseline-profile` module.\n baselineProfile(project(\":baseline-profile\"))\n}\n\n// Baseline Profile Gradle plugin configuration.\nbaselineProfile {\n\n // /topic/performance/baselineprofile/configure-baselineprofiles#filter-profile-rules the generated profile rules. \n // This example keeps the classes in the `com.library` package all its subpackages.\n filter {\n include \"com.mylibrary.**\"\n }\n}\n```\n\n### Groovy\n\n```groovy\nplugins {\n id 'com.android.library'\n id 'androidx.baselineprofile'\n}\n\nandroid { ... }\n\ndependencies {\n ...\n // Add a baselineProfile dependency to the `:baseline-profile` module.\n baselineProfile ':baseline-profile'\n}\n\n// Baseline Profile Gradle plugin configuration.\nbaselineProfile {\n\n // /topic/performance/baselineprofile/configure-baselineprofiles#filter-profile-rules the generated profile rules. \n // This example keeps the classes in the `com.library` package all its subpackages.\n filter {\n include 'com.mylibrary.**'\n }\n}\n```\n5. Add the `androidx.baselineprofile` plugin to the `build.gradle.kts` file in the app module `:sample-app`. \n\n ### Kotlin\n\n ```kotlin\n plugins {\n ...\n id(\"androidx.baselineprofile\")\n }\n ```\n\n ### Groovy\n\n ```groovy\n plugins {\n ...\n id 'androidx.baselineprofile'\n }\n ```\n6. Generate the profile by running the following code: `./gradlew :library:generateBaselineProfile`.\n\nAt the end of the generation task, the Baseline Profile is stored at\n`library/src/main/generated/baselineProfiles`."]]