כדי ליצור פרופילים בסיסיים של ספרייה, צריך להשתמש הפלאגין Baseline Profile Gradle
יצירת פרופילים בסיסיים של ספרייה כוללת שלושה מודולים:
- מודול אפליקציה לדוגמה: מכיל את האפליקציה לדוגמה שמשתמשת בספרייה שלך.
- מודול ספרייה: המודול שעבורו רוצים ליצור פרופיל.
- המודול של פרופיל הבסיס: מודול הבדיקה שיוצר את הפרופילים של קבוצת הבסיס.
כדי ליצור פרופיל Baseline לספרייה, מבצעים את השלבים הבאים:
- יוצרים מודול com.android.testחדש, לדוגמה,:baseline-profile.
- מגדירים את הקובץ build.gradle.ktsעבור מודול:baseline-profile. התצורה היא כמעט זהות לאלה של אפליקציה, אבל חשוב להגדירtargetProjectPathלמודול האפליקציה לדוגמה.
- יצירת בדיקה של פרופיל בסיס ב-:baseline-profileמודול הבדיקה. הכתובת צריכה להיות ספציפית לאפליקציה לדוגמה ולכלול את כל הפונקציות של הספרייה.
- מעדכנים את ההגדרות בקובץ build.gradle.ktssדרך של מודול ספריה, למשל:library.
- מחילים את הפלאגין androidx.baselineprofile.
- צריך להוסיף תלות ב-baselineProfileל- מודול:baseline-profile.
- מחילים את התצורה הרצויה של יישומי הפלאגין לצרכנים, כפי שמתואר בקטע בדוגמה הבאה.
- מוסיפים את הפלאגין androidx.baselineprofileאל הקובץbuild.gradle.ktsבמודול האפליקציה:sample-app.Kotlinplugins { ... id("androidx.baselineprofile") } מגניבplugins { ... id 'androidx.baselineprofile' } 
- כדי ליצור את הפרופיל, מריצים את הקוד הבא:
  ./gradlew :library:generateBaselineProfile
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.**" } }
מגניב
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.**' } }
בסוף משימת היצירה, פרופיל הבסיס מאוחסן ב
library/src/main/generated/baselineProfiles
