יצירת פרופילים בסיסיים של הספרייה

כדי ליצור פרופילים בסיסיים של ספרייה, צריך להשתמש הפלאגין Baseline Profile Gradle

יצירת פרופילים בסיסיים של ספרייה כוללת שלושה מודולים:

  • מודול אפליקציה לדוגמה: מכיל את האפליקציה לדוגמה שמשתמשת בספרייה שלך.
  • מודול ספרייה: המודול שעבורו רוצים ליצור פרופיל.
  • המודול של פרופיל הבסיס: מודול הבדיקה שיוצר את הפרופילים של קבוצת הבסיס.

כדי ליצור פרופיל Baseline לספרייה, מבצעים את השלבים הבאים:

  1. יוצרים מודול com.android.test חדש, לדוגמה, :baseline-profile.
  2. מגדירים את הקובץ build.gradle.kts עבור מודול :baseline-profile. התצורה היא כמעט זהות לאלה של אפליקציה, אבל חשוב להגדיר targetProjectPath למודול האפליקציה לדוגמה.
  3. יצירת בדיקה של פרופיל בסיס ב-:baseline-profile מודול הבדיקה. הכתובת צריכה להיות ספציפית לאפליקציה לדוגמה ולכלול את כל הפונקציות של הספרייה.
  4. מעדכנים את ההגדרות בקובץ build.gradle.ktss דרך של מודול ספריה, למשל :library.
    1. מחילים את הפלאגין androidx.baselineprofile.
    2. צריך להוסיף תלות ב-baselineProfile ל- מודול :baseline-profile.
    3. מחילים את התצורה הרצויה של יישומי הפלאגין לצרכנים, כפי שמתואר בקטע בדוגמה הבאה.

    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.**'
        }
    }
    
  5. מוסיפים את הפלאגין androidx.baselineprofile אל הקובץ build.gradle.kts במודול האפליקציה :sample-app.

    Kotlin

    plugins {
        ...
        id("androidx.baselineprofile")
    }
    

    מגניב

    plugins {
        ...
        id 'androidx.baselineprofile'
    }
    
  6. כדי ליצור את הפרופיל, מריצים את הקוד הבא: ./gradlew :library:generateBaselineProfile

בסוף משימת היצירה, פרופיל הבסיס מאוחסן ב library/src/main/generated/baselineProfiles