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

Ely*_*lye 5 android android-jetpack-compose

当我将我的撰写版本从 升级1.0.0-beta01到时出现此错误1.0.0-beta02 (并且还需要从 kotlin-gradle-plugin 升级1.4.301.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()`.
Run Code Online (Sandbox Code Playgroud)
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
    }
}
Run Code Online (Sandbox Code Playgroud)

我的依赖如下

    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'
Run Code Online (Sandbox Code Playgroud)

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

我该如何解决?

ian*_*ake 11

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

implementation 'androidx.appcompat:appcompat:1.3.0-beta01'
Run Code Online (Sandbox Code Playgroud)

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