You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Android Studio 2021.2.1 Patch 2中升级Jetpack Compose至1.2.0-beta01失败求助

Fixing Jetpack Compose 1.2.0-beta01 Upgrade Failure

Hey there! I get it, upgrading Compose versions can feel tricky when you're just starting out with Android development. The main issue here is that Jetpack Compose versions are tightly tied to specific Kotlin compiler versions—changing only the compose_version without updating your Kotlin setup is what's causing the build failure. Let's fix this step by step.

Step 1: Update Kotlin Version to Match Compose 1.2.0-beta01

Compose 1.2.0-beta01 requires Kotlin 1.7.10 (you’re currently on 1.5.31, which is incompatible). Here’s how to update your top-level build.gradle file:

buildscript {
    ext {
        compose_version = '1.2.0-beta01' // Updated Compose version
    }
}// Top-level build file where you can add configuration options common to all sub-projects/modules.
plugins {
    id 'com.android.application' version '7.2.2' apply false
    id 'com.android.library' version '7.2.2' apply false
    id 'org.jetbrains.kotlin.android' version '1.7.10' apply false // Updated Kotlin version
}
task clean(type: Delete) {
    delete rootProject.buildDir
}

To avoid potential compatibility issues with other core libraries, it’s a good idea to update some dependencies to versions that play well with Compose 1.2.0-beta01. Here’s the modified app/build.gradle dependencies block:

dependencies {
    implementation 'androidx.core:core-ktx:1.9.0'
    implementation "androidx.compose.ui:ui:$compose_version"
    implementation "androidx.compose.material:material:$compose_version"
    implementation "androidx.compose.ui:ui-tooling-preview:$compose_version"
    implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.5.1' // Updated lifecycle dependency
    implementation 'androidx.activity:activity-compose:1.5.1' // Updated activity-compose dependency
    testImplementation 'junit:junit:4.13.2'
    androidTestImplementation 'androidx.test.ext:junit:1.1.5'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
    androidTestImplementation "androidx.compose.ui:ui-test-junit4:$compose_version"
    debugImplementation "androidx.compose.ui:ui-tooling:$compose_version"
    debugImplementation "androidx.compose.ui:ui-test-manifest:$compose_version"
}

Step 3: Clean and Sync Your Project

After making these changes:

  1. Click Sync Project with Gradle Files in Android Studio to apply the updates.
  2. If you still see errors, go to File > Invalidate Caches... > Invalidate and Restart to clear any cached build files that might be causing conflicts.

Why This Works

Jetpack Compose relies on the Kotlin Compiler Extension, which has strict version matching rules with the Kotlin language itself. Compose 1.2.x versions require Kotlin 1.7.x, so skipping that update was breaking your build. Updating both versions together ensures full compatibility.

If you run into any specific error messages after these changes, feel free to share them and we can troubleshoot further!

内容的提问来源于stack exchange,提问作者Aadish Jain

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.27 14:07:33