기준 프로필 Gradle 플러그인을 사용하면 기준 프로필을 더 쉽게 생성하고 유지관리할 수 있습니다. 이는 다음 작업을 수행하는 데 도움이 됩니다.
- 앱의 새 기준 프로필 생성.
- 라이브러리의 새 기준 프로필 생성.
- 기준 프로필 생성의 맞춤설정.
이 페이지에서는 기준 프로필 Gradle 플러그인을 사용하여 기준 프로필 생성을 맞춤설정하는 방법을 설명합니다.
플러그인 요구사항
- AGP 8.0 이상
- 최신 Gradle 플러그인 버전에 종속
Gradle 관리 기기를 사용하여 기준 프로필 생성
Gradle 관리 기기(GMD)를 사용하여 기준 프로필을 생성하려면, 다음 예에 나와 있는 것처럼 프로필 제작자 모듈(:baselineprofile
테스트 모듈일 수 있음)의 build.gradle.kts
구성에 기준 프로필을 추가합니다.
Kotlin
android { testOptions.managedDevices.devices { create<com.android.build.api.dsl.ManagedVirtualDevice>("pixel6Api31") { device = "Pixel 6" apiLevel = 31 systemImageSource = "aosp" } } }
Groovy
android { testOptions.managedDevices.devices { pixel6Api31(ManagedVirtualDevice) { device 'Pixel 6' apiLevel = 31 systemImageSource 'aosp' } } }
GMD를 사용하면 다음과 같이 기준 프로필 Gradle 플러그인 구성에 기준 프로필을 추가하여 기준 프로필을 생성할 수 있습니다.
Kotlin
baselineProfile { managedDevices += "pixel6Api31" }
Groovy
baselineProfile { managedDevices = ['pixel6Api31'] }
GMD를 사용하여 기준 프로필을 생성할 경우 useConnectedDevices
를 false
로 설정합니다.
Kotlin
baselineProfile { ... useConnectedDevices = false }
Groovy
baselineProfile { ... useConnectedDevices false }
여러 변형을 위한 기준 프로필 생성
변형별, 버전별 또는 모든 변형에 사용할 단일 파일로 기준 프로필을 생성할 수 있습니다. 다음 예와 같이 병합 설정을 통해 이 동작을 제어합니다.
Kotlin
baselineProfile { mergeIntoMain = true }
Groovy
baselineProfile { mergeIntoMain true }
모든 변형에 대해 생성된 프로필을 단일 프로필로 병합하려면 mergeIntoMain
을 true
로 설정합니다. 이 설정이 true
인 경우 변형별 기준 프로필을 생성할 수 없으므로 generateBaselineProfile
이라는 단일 Gradle 작업이 존재합니다. 프로필은 src/main/generated/baselineProfiles
에 출력됩니다.
병합을 중지하고 변형별 프로필을 하나씩 가지려면 mergeIntoMain
을 false
로 설정합니다. 이 경우 변형별 Gradle 작업이 여러 개 존재합니다. 예를 들어, 두 가지 버전(예: 무료 및 유료)과 하나의 출시 빌드 유형이 있는 경우 작업은 다음과 같습니다.
* `generateFreeReleaseBaselineProfile`
* `generatePaidReleaseBaselineProfile`
* `generateReleaseBaselineProfile`
변형별로 병합 동작을 지정하려면 다음 코드를 사용합니다.
Kotlin
baselineProfile { variants { freeRelease { mergeIntoMain = true } } }
Groovy
baselineProfile { variants { freeRelease { mergeIntoMain true } } }
위의 예에서 플래그가 true
로 설정된 변형이 모두 src/main/generated/baselineProfiles
에 병합되고, 플래그가 false
로 설정된 변형의 프로필은 src/<variant>/generated/baselineProfiles
폴더에 보관되었습니다.
기본적으로 mergeIntoMain
은 라이브러리에는 true
로, 앱에는 false
로 설정됩니다.
새 출시 버전 조합 시 기준 프로필 자동 생성
generateBaselineProfile
작업을 수동으로 사용하는 대신 모든 출시 빌드에서 자동으로 생성되도록 기준 프로필을 구성할 수 있습니다. 자동 생성을 사용하면 최신 프로필이 출시 빌드에 포함됩니다.
출시 빌드에 자동 생성을 사용 설정하려면 automaticGenerationDuringBuild
플래그를 사용합니다.
Kotlin
baselineProfile { automaticGenerationDuringBuild = true }
Groovy
baselineProfile { automaticGenerationDuringBuild true }
automaticGenerationDuringBuild
플래그를 true
로 설정하면 각 출시 어셈블리의 새 기준 프로필 생성이 트리거됩니다. 즉, ./gradlew:app:assembleRelease
와 같은 조합 출시 빌드 작업을 실행하면 :app:generateReleaseBaselineProfile
도 트리거되고 기준 프로필 계측 테스트가 시작되며 테스트가 실행되는 기준 프로필 빌드가 빌드됩니다.
자동 생성이 사용자에게 최고의 성능 이점을 얻는 데 도움이 되지만, 이중 빌드 및 계측 테스트로 인해 빌드 시간이 늘어나기도 합니다.
다음 예에서와 같이 이 동작을 변형별로 지정할 수도 있습니다.
Kotlin
baselineProfile { variants { freeRelease { automaticGenerationDuringBuild = true } } }
Groovy
baselineProfile { variants { freeRelease { automaticGenerationDuringBuild true } } }
앞의 예에서 generateFreeReleaseBaselineProfile
작업은 assembleFreeRelease
를 시작하면 실행됩니다. 이는 사용자가 빌드할 때 항상 프로필을 생성하는 배포 빌드에 release
를 사용하고 내부 테스트를 위해 releaseWithoutProfile
빌드를 사용하려는 경우에 유용합니다.
소스에 기준 프로필 저장
saveInSrc
플래그를 통해 기준 프로필을 소스 디렉터리에 저장할 수 있습니다.
true
: 기준 프로필이src/<variant>/generated/baselineProfiles
에 저장됩니다. 이렇게 하면 가장 최근에 생성된 프로필을 소스와 함께 커밋할 수 있습니다.false
: 기준 프로필이 빌드 디렉터리의 임시 파일에 저장됩니다. 이렇게 하면 코드를 커밋할 때 가장 최근에 생성된 프로필이 저장되지 않습니다.
Kotlin
baselineProfile { saveInSrc = true }
Groovy
baselineProfile { saveInSrc true }
이 동작을 변형별로 지정할 수도 있습니다.
Kotlin
baselineProfile { variants { freeRelease { saveInSrc = true } } }
Groovy
baselineProfile { variants { freeRelease { saveInSrc true } } }
프로필 규칙 필터링
기준 프로필 Gradle 플러그인을 사용하면 생성된 기준 프로필 규칙을 필터링할 수 있습니다. 이는 샘플 앱이나 라이브러리 자체의 다른 종속 항목의 일부인 클래스 및 메서드에 대해 프로필 규칙을 제외하려는 경우에 특히 유용합니다. 필터는 특정 패키지 및 클래스를 포함하거나 제외할 수 있습니다. 제외만 지정하면 일치하는 기준 프로필 규칙만 제외되고 나머지는 모두 포함됩니다.
필터 사양은 다음 중 하나일 수 있습니다.
- 지정된 패키지 및 모든 하위 패키지와 일치하도록 이중 와일드 카드로 끝나는 패키지 이름. 예를 들어
com.example.**
은com.example.method
및com.example.method.bar
와 일치합니다. - 지정된 패키지하고만 일치하도록 와일드 카드로 끝나는 패키지 이름. 예를 들어
com.example.*
은com.example.method
와 일치하지만com.example.method.bar
와는 일치하지 않습니다. - 특정 클래스와 일치하는 클래스 이름(예:
com.example.MyClass
).
다음 예는 특정 패키지를 포함하거나 제외하는 방법을 보여줍니다.
Kotlin
baselineProfile { filter { include("com.somelibrary.widget.grid.**") exclude("com.somelibrary.widget.grid.debug.**") include("com.somelibrary.widget.list.**") exclude("com.somelibrary.widget.list.debug.**") include("com.somelibrary.widget.text.**") exclude("com.somelibrary.widget.text.debug.**") } }
Groovy
baselineProfile { filter { include 'com.somelibrary.widget.grid.**' exclude 'com.somelibrary.widget.grid.debug.**' include 'com.somelibrary.widget.list.**' exclude 'com.somelibrary.widget.list.debug.**' include 'com.somelibrary.widget.text.**' exclude 'com.somelibrary.widget.text.debug.**' } }
다음과 같이 다양한 변형을 위한 필터 규칙을 맞춤설정합니다.
Kotlin
// Non-specific filters applied to all the variants. baselineProfile { filter { include("com.myapp.**") } } // Flavor-specific filters. baselineProfile { variants { free { filter { include("com.myapp.free.**") } } paid { filter { include("com.myapp.paid.**") } } } } // Build-type-specific filters. baselineProfile { variants { release { filter { include("com.myapp.**") } } } } // Variant-specific filters. baselineProfile { variants { freeRelease { filter { include("com.myapp.**") } } } }
Groovy
// Non-specific filters applied to all the variants. baselineProfile { filter { include 'com.myapp.**' } } // Flavor-specific filters. baselineProfile { variants { free { filter { include 'com.myapp.free.**' } } paid { filter { include 'com.myapp.paid.**' } } } } // Build-type specific filters. baselineProfile { variants { release { filter { include 'com.myapp.**' } } } } // Variant-specific filters. baselineProfile { variants { freeRelease { filter { include 'com.myapp.**' } } } }
BaselineProfileRule.collect()
에서 filterPredicate
인수를 사용하여 규칙을 필터링할 수도 있지만 Gradle 플러그인을 사용하여 필터링하는 것이 좋습니다. 하위 패키지를 필터링하는 더 간단한 방법과 전체 모듈을 구성하는 단일 위치를 제공하기 때문입니다.
벤치마크 및 기준 프로필 빌드 유형 맞춤설정
기준 프로필 Gradle 플러그인은 프로필을 생성하고 벤치마크를 실행하기 위한 추가 빌드 유형을 생성합니다. 이러한 빌드 유형은 benchmark
및 nonMinified
라는 접두사가 붙습니다. 예를 들어 release
빌드 유형의 경우 플러그인이 benchmarkRelease
및 nonMinifiedRelease
빌드 유형을 생성합니다.
이러한 빌드 유형은 특정 사용 사례에 맞게 자동으로 구성되며 일반적으로 맞춤설정이 필요하지 않습니다. 하지만 다른 서명 구성을 적용하는 것과 같이 일부 맞춤 옵션을 적용하는 것이 유용한 경우도 있습니다.
빌드 유형 속성의 하위 집합을 사용하여 자동 생성된 빌드 유형을 맞춤설정할 수 있습니다. 사용할 수 없는 속성은 재정의됩니다. 다음 예는 추가 빌드 유형을 맞춤설정하는 방법과 재정의되는 속성을 보여줍니다.
Kotlin
android { buildTypes { release { ... } benchmarkRelease { // Customize properties for the `benchmarkRelease` build type here. // For example, you can change the signing config (by default // it's the same as for the `release` build type). signingConfig = signingConfigs.getByName("benchmarkRelease") } nonMinifiedRelease { // Customize properties for the `nonMinifiedRelease` build type here. signingConfig = signingConfigs.getByName("nonMinifiedRelease") // From Baseline Profile Gradle plugin 1.2.4 and higher, you can't // customize the following properties, which are always overridden to // avoid breaking Baseline Profile generation: // // isJniDebuggable = false // isDebuggable = false // isMinifyEnabled = false // isShrinkResources = false // isProfileable = true // enableAndroidTestCoverage = false // enableUnitTestCoverage = false } } }
Groovy
android { buildTypes { release { ... } benchmarkRelease { // Customize properties for the `benchmarkRelease` build type here. // For example, you can change the signing config (by default it's the // same as for the `release` build type.) signingConfig = signingConfigs.benchmarkRelease } nonMinifiedRelease { // Customize properties for the `nonMinifiedRelease` build type here. signingConfig = signingConfigs.nonMinifiedRelease // From Baseline Profile Gradle plugin 1.2.4 and higher, you can't use // the following properties, which are always overridden to avoid breaking // Baseline Profile generation: // // isJniDebuggable = false // isDebuggable = false // isMinifyEnabled = false // isShrinkResources = false // isProfileable = true // enableAndroidTestCoverage = false // enableUnitTestCoverage = false } } }
추가 참고사항
기준 프로필을 만들 때 다음 사항에 유의하세요.
컴파일된 기준 프로필은 1.5MB 미만이어야 합니다. 이는 일반적으로 컴파일 전에 훨씬 더 큰 소스 파일의 텍스트 형식에는 적용되지 않습니다. APK의 경우
assets/dexopt/baseline.prof
, AAB의 경우BUNDLE-METADATA/com.android.tools.build.profiles/baseline.prof
아래의 출력 아티팩트에서 바이너리 기준 프로필을 찾아 프로필의 크기를 확인합니다.애플리케이션의 너무 많은 부분을 컴파일하는 광범위한 규칙은 디스크 액세스 횟수가 늘기 때문에 시작 속도를 느리게 만들 수 있습니다. 기준 프로필을 이제 막 사용하기 시작한 경우에는 시작 속도를 걱정하지 않아도 됩니다. 그러나 앱에 따라, 그리고 여정의 개수에 따라, 많은 여정을 추가하면 성능이 저하될 수 있습니다. 다양한 프로필을 시도하고 여정 추가로 인해 성능이 저하되지 않았는지 확인하여 앱 성능을 테스트하세요.