Basisprofile für eine Bibliothek erstellen
Mit Sammlungen den Überblick behalten
Sie können Inhalte basierend auf Ihren Einstellungen speichern und kategorisieren.
Verwenden Sie zum Erstellen von Basisprofilen für eine Bibliothek die Methode
Gradle-Plug-in für Referenzprofil
Die Erstellung von Baseline-Profilen für eine Bibliothek umfasst drei Module:
- Beispielanwendungsmodul: enthält die Beispielanwendung, die Ihre Bibliothek verwendet.
- Bibliotheksmodul: das Modul, für das Sie das Profil erstellen möchten.
- Baseline-Profilmodul: Das Testmodul, das die Baseline-Profile generiert.
So generieren Sie ein Basisprofil für eine Bibliothek:
- Erstellen Sie ein neues
com.android.test
-Modul. Beispiel:
:baseline-profile
.
- Konfigurieren Sie die Datei
build.gradle.kts
für die
Modul :baseline-profile
. Die Konfiguration ist
im Grunde wie für eine App, müssen aber die
targetProjectPath
auf das Beispiel-App-Modul.
- Baseline-Profiltest in
:baseline-profile
erstellen
Testmodul. Dies muss für die Beispiel-App spezifisch sein und alle
die Funktionen der Bibliothek.
- Aktualisieren Sie die Konfiguration in der Datei
build.gradle.ktss
in der
Bibliotheksmodul, sagen Sie :library
.
- Wenden Sie das Plug-in
androidx.baselineprofile
an.
- Fügen Sie eine
baselineProfile
-Abhängigkeit zum
Modul :baseline-profile
.
- Wenden Sie die gewünschte Konfiguration des Nutzer-Plug-ins an, wie in den
folgenden Beispiel.
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.**"
}
}
Cool
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.**'
}
}
- Fügen Sie das Plug-in
androidx.baselineprofile
zum
Datei build.gradle.kts
im App-Modul
:sample-app
Kotlin
plugins {
...
id("androidx.baselineprofile")
}
Cool
plugins {
...
id 'androidx.baselineprofile'
}
- Generieren Sie das Profil, indem Sie den folgenden Code ausführen:
./gradlew :library:generateBaselineProfile
Am Ende der Generierungsaufgabe wird das Baseline-Profil gespeichert unter
library/src/main/generated/baselineProfiles
Alle Inhalte und Codebeispiele auf dieser Seite unterliegen den Lizenzen wie im Abschnitt Inhaltslizenz beschrieben. Java und OpenJDK sind Marken oder eingetragene Marken von Oracle und/oder seinen Tochtergesellschaften.
Zuletzt aktualisiert: 2025-07-27 (UTC).
[null,null,["Zuletzt aktualisiert: 2025-07-27 (UTC)."],[],[],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`."]]