본문 바로가기

안드로이드

compose 넣은 xml 불러오면 에러날 때

반응형
java.lang.IllegalStateException: ViewTreeLifecycleOwner not found from androidx.coordinatorlayout.widget.CoordinatorLayout{25a0d04 V.E...... ......ID 0,0-0,0 #7f090122 app:id/common_container}
        at androidx.compose.ui.platform.WindowRecomposer_androidKt.createLifecycleAwareViewTreeRecomposer(WindowRecomposer.android.kt:244)
        at androidx.compose.ui.platform.WindowRecomposer_androidKt.access$createLifecycleAwareViewTreeRecomposer(WindowRecomposer.android.kt:1)
        at androidx.compose.ui.platform.WindowRecomposerFactory$Companion$LifecycleAware$1.createRecomposer(WindowRecomposer.android.kt:99)
        at androidx.compose.ui.platform.WindowRecomposerPolicy.createAndInstallWindowRecomposer$ui_release(WindowRecomposer.android.kt:155)
        at androidx.compose.ui.platform.WindowRecomposer_androidKt.getWindowRecomposer(WindowRecomposer.android.kt:230)
        at androidx.compose.ui.platform.AbstractComposeView.resolveParentCompositionContext(ComposeView.android.kt:220)
        at androidx.compose.ui.platform.AbstractComposeView.ensureCompositionCreated(ComposeView.android.kt:227)
        at androidx.compose.ui.platform.AbstractComposeView.onAttachedToWindow(ComposeView.android.kt:259)

기존 프로젝트에 Compose 를 넣어보려고 커스텀 뷰를 AbstractComposeView 로 전환하고 기존 xml 에 넣고 빌드를 돌리니

위와 같은 에러가 발생했다.

ViewTreeLifecycleOwner 이 없다고 나오는데

LifeCycleOwner 를 쉽게 얻을 수 있도록 나온 새로운 API 이다.

xml 을 불러올 때 포함된 AbstractComposeView 가 사용할 context 를 가져올 때
ViewTreeLifecycleOwner 를 사용하고 있다.

androidx.appcompat:appcompat:1.3.0

ViewTreeLifecycleOwner 는 appCompat 1.3.0 부터 추가 되어있으니 버전을 올려주면 빌드가 잘된다.

 
반응형