本文介绍了androidx.appcompat.app.AppCompatActivity未实现LifecycleOwner的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道看起来像是一些愚蠢的错误,但我找不到它.在我的项目中,我可以从片段中访问LifecycleOwner,但不能从活动中访问.

I know looks like some stupid error, but I cannot find it.In my project I have access to LifecycleOwner from my Fragments but not from Activity.

这是我的build.gradle

implementation project(':domain')
implementation project(':data')
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.1.1'
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.1.1'
implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'androidx.core:core-ktx:1.1.0-alpha05'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'

// Koin for Android
implementation "org.koin:koin-android:$koin_version"
implementation "org.koin:koin-androidx-viewmodel:$koin_version"

// Anko
implementation "org.jetbrains.anko:anko-commons:$anko_version"
implementation "org.jetbrains.anko:anko-sdk15-listeners:$anko_version"

//Architecture components
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation "androidx.lifecycle:lifecycle-extensions:$lifecycle_version"
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:$lifecycle_version"

这是活动代码:

这是AppCompatActivity的源代码

推荐答案

根据此问题 ,如果您使用core-ktx:1.1.0appcompat:1.0.2并将alpha版本与稳定版本混合使用,则这是一个已知问题.升级到appcompat:1.1.0-alpha03即可解决问题:

As per this issue, this is a known issue if you use core-ktx:1.1.0 and appcompat:1.0.2, mixing alpha versions with stable releases. Upgrade to appcompat:1.1.0-alpha03 to fix the issue:

implementation 'androidx.appcompat:appcompat:1.1.0-alpha03'

这篇关于androidx.appcompat.app.AppCompatActivity未实现LifecycleOwner的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-14 20:06