如果您要将此 ComposeView 添加到 AppCompatActivity,请确保您使用的是 AppCompat 版本 1.3+

If you are adding this ComposeView to an AppCompatActivity, make sure you are using AppCompat version 1.3+

我将撰写版本从 1.0.0-beta01 升级到 1.0.0-beta02 时出现此错误 (并且还需要从 kotlin-gradle-plugin 从 1.4.30 升级到 1.4.31。)

java.lang.IllegalStateException: ViewTreeLifecycleOwner not set for this ComposeView. 
If you are adding this ComposeView to an AppCompatActivity, make sure you are using AppCompat version 1.3+. 
If you are adding this ComposeView to a Fragment, make sure you are using Fragment version 1.3+. 
For other cases, manually set owners on this view by using `ViewTreeLifecycleOwner.set()` and `ViewTreeSavedStateRegistryOwner.set()`.
buildscript {
    ext {
        compose_version = '1.0.0-beta02'
    }
    repositories {
        google()
        mavenCentral()
    }
    dependencies {
        classpath "com.android.tools.build:gradle:7.0.0-alpha08"
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.4.31"

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

我的依赖如下

    implementation 'androidx.core:core-ktx:1.3.2'
    implementation 'androidx.appcompat:appcompat:1.2.0'
    implementation 'com.google.android.material:material:1.3.0'
    implementation "androidx.compose.ui:ui:$compose_version"
    implementation "androidx.compose.material:material:$compose_version"
    implementation "androidx.compose.ui:ui-tooling:$compose_version"
    implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.3.0'
    implementation 'androidx.activity:activity-compose:1.3.0-alpha03'
    implementation 'dev.chrisbanes.accompanist:accompanist-insets:0.6.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
    testImplementation 'junit:junit:4.13.2'
    androidTestImplementation 'androidx.test.ext:junit:1.1.2'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'

我确实尝试将我的 androidx.appcompat:appcompat 依赖项从 1.2.0 升级到 1.3.0,它会出错 Could not find androidx.appcompat:appcompat:1.3.0.

我该如何解决?

此时,最新的 AppCompat 版本是 AppCompat 1.3.0-beta01:

implementation 'androidx.appcompat:appcompat:1.3.0-beta01'

目前还没有支持 Compose 所需要求的稳定版本的 AppCompat。