라이브러리의 기준 프로필 만들기

라이브러리의 기준 프로필을 만들려면 기준 프로필 Gradle 플러그인을 사용하세요.

라이브러리의 기준 프로필 생성과 관련된 세 가지 모듈은 다음과 같습니다.

  • 샘플 앱 모듈: 라이브러리를 사용하는 샘플 앱이 포함되어 있습니다.
  • 라이브러리 모듈: 프로필을 생성하려는 모듈입니다.
  • 기준 프로필 모듈: 기준 프로필을 생성하는 테스트 모듈입니다.

라이브러리용 기준 프로필을 생성하려면 다음 단계를 따르세요.

  1. com.android.test 모듈을 만듭니다(예: :baseline-profile).
  2. :baseline-profile 모듈의 build.gradle.kts 파일을 구성합니다. 구성은 기본적으로 앱과 동일하지만 targetProjectPath를 샘플 앱 모듈로 설정해야 합니다.
  3. :baseline-profile 테스트 모듈에서 기준 프로필 테스트를 만듭니다. 이는 샘플 앱에만 해당하는 테스트여야 하며 라이브러리의 모든 기능을 사용해야 합니다.
  4. 라이브러리 모듈(예: :library)의 build.gradle.ktss 파일에서 구성을 업데이트합니다.
    1. androidx.baselineprofile 플러그인을 적용합니다.
    2. :baseline-profile 모듈에 baselineProfile 종속 항목을 추가합니다.
    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.**"
        }
    }
    

    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.**'
        }
    }
    
  5. androidx.baselineprofile 플러그인을 앱 모듈 :sample-appbuild.gradle.kts 파일에 추가합니다.

    Kotlin

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

    Groovy

    plugins {
        ...
        id 'androidx.baselineprofile'
    }
    
  6. ./gradlew :library:generateBaselineProfile 코드를 실행하여 프로필을 생성합니다.

생성 작업이 끝나면 기준 프로필이 library/src/main/generated/baselineProfiles에 저장됩니다.