ライブラリのベースライン プロファイルを作成する
コレクションでコンテンツを整理
必要に応じて、コンテンツの保存と分類を行います。
ライブラリのベースライン プロファイルを作成するには、ベースライン プロファイル Gradle プラグインを使用します。
ライブラリのベースライン プロファイルの作成には、次の 3 つのモジュールが使用されます。
- サンプルアプリ モジュール: ライブラリを使用するサンプルアプリが含まれています。
- ライブラリ モジュール: プロファイルを生成するモジュール。
- ベースライン プロファイル モジュール: ベースライン プロファイルを生成するテスト モジュール。
ライブラリのベースライン プロファイルを生成する手順は次のとおりです。
- 新しい
com.android.test
モジュールを作成します(例: :baseline-profile
)。
:baseline-profile
モジュールの build.gradle.kts
ファイルを構成します。構成は基本的にアプリの場合と同じですが、必ず 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 UTC。
[[["わかりやすい","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 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`."]]