Tech Sheets

Ensuring Version Compatibility with Jetpack Compose BOM

最終更新日:2024-06-16

Jetpack Compose is under constant development, and directly specifying library versions can lead to compatibility issues.To ensure a stable and consistent experience, Google provides a Bill of Materials (BOM) that defines compatible versions of all Compose libraries.

Official document is here

Add the BOM

Import the Compose BOM in your app/build.gradle.kts file. This will manage the versions of all Compose libraries.

// build.gradle.kts
val composeBom = platform("androidx.compose:compose-bom:2024.05.00")
implementation(composeBom)
testImplementation(composeBom)
androidTestImplementation(composeBom)

Omit Version Numbers

Since the BOM manages versions, you can omit version numbers for individual Compose libraries.

// build.gradle.kts
implementation("androidx.compose.ui:ui")
implementation("androidx.compose.ui:ui-tooling-preview")
implementation("androidx.compose.material3:material3")

androidTestImplementation("androidx.compose.ui:ui-test-junit4")
debugImplementation("androidx.compose.ui:ui-tooling")
debugImplementation("androidx.compose.ui:ui-test-manifest")

Finalized build.gradle.kts

The dependencies section should look like this

dependencies {
  // Add the BOM (and remember to add it to testImplementation, etc.)
  val composeBom = platform("androidx.compose:compose-bom:2024.05.00")
  implementation(composeBom)
  testImplementation(composeBom)
  androidTestImplementation(composeBom)

  // Omit version numbers
  implementation("androidx.compose.ui:ui")
  implementation("androidx.compose.ui:ui-tooling-preview")
  implementation("androidx.compose.material3:material3")

  androidTestImplementation("androidx.compose.ui:ui-test-junit4")
  debugImplementation("androidx.compose.ui:ui-tooling")
  debugImplementation("androidx.compose.ui:ui-test-manifest")
}

By following these steps, you can ensure that your Jetpack Compose project is always using compatible versions of all libraries, leading to a more stable and consistent development experience.

一覧に戻る