Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I got this error when I upgrade my compose version from 1.0.0-beta01 to 1.0.0-beta02 (and also need to upgrade from kotlin-gradle-plugin from 1.4.30 to 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
    }
}

My dependencies are as below

    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'

I did try to upgrade my androidx.appcompat:appcompat dependencies from 1.2.0 to 1.3.0, it will error stating Could not find androidx.appcompat:appcompat:1.3.0..

How can I resolve it?

like image 242
Elye Avatar asked Mar 13 '21 04:03

Elye


People also ask

What is Androidx AppCompat app AppCompatActivity?

androidx.appcompat.app.AppCompatActivity. Base class for activities that wish to use some of the newer platform features on older Android devices. Some of these backported features include: Using the action bar, including action items, navigation modes and more with the setSupportActionBar(Toolbar) API.

Can I add jetpack compose to existing project?

If you want to use Jetpack Compose in an existing project, you'll need to configure your project with required settings and dependencies.

What is AppCompat library?

When new versions of android are published, Google will have to support the older versions of android. So AppCompat is a set of support libraries which can be used to make the apps developed with newer versions work with older versions.


1 Answers

At this time, the latest AppCompat release is AppCompat 1.3.0-beta01:

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

There is no stable version of AppCompat that supports the requirements that Compose needs as of yet.

like image 83
ianhanniballake Avatar answered Sep 21 '22 10:09

ianhanniballake