Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crash with ViewModel 2.8 #2677

Open
Pitel opened this issue May 16, 2024 · 5 comments
Open

Crash with ViewModel 2.8 #2677

Pitel opened this issue May 16, 2024 · 5 comments

Comments

@Pitel
Copy link

Pitel commented May 16, 2024

Description

LeakCanary is not working with ViewModel 2.8, causing crash

Steps to Reproduce

  1. Have a working project with LC 2.14 and ViewModel 2.7
  2. Upgrade to VM 2.8
  3. Observe crash

Expected behavior: Not crashing

Version Information

  • LeakCanary version: 2.14
  • Android OS version: Irrelevant
  • Gradle version: Irrelevant

Additional Information

java.lang.AbstractMethodError: abstract method "androidx.lifecycle.ViewModel androidx.lifecycle.ViewModelProvider$Factory.create(kotlin.reflect.KClass, androidx.lifecycle.viewmodel.CreationExtras)"
                            	at androidx.lifecycle.viewmodel.ViewModelProviderImpl.getViewModel$lifecycle_viewmodel_release(ViewModelProviderImpl.kt:69)
                            	at androidx.lifecycle.viewmodel.ViewModelProviderImpl.getViewModel$lifecycle_viewmodel_release$default(ViewModelProviderImpl.kt:47)
                            	at androidx.lifecycle.ViewModelProvider.get(ViewModelProvider.android.kt:91)
                            	at androidx.lifecycle.ViewModelProvider.get(ViewModelProvider.android.kt:109)
                            	at leakcanary.internal.ViewModelClearedWatcher$Companion.install(ViewModelClearedWatcher.kt:61)
                            	at leakcanary.internal.AndroidXFragmentDestroyWatcher.invoke(AndroidXFragmentDestroyWatcher.kt:66)
                            	at leakcanary.internal.AndroidXFragmentDestroyWatcher.invoke(AndroidXFragmentDestroyWatcher.kt:25)
                            	at leakcanary.FragmentAndViewModelWatcher$lifecycleCallbacks$1.onActivityCreated(FragmentAndViewModelWatcher.kt:59)
@pyricau
Copy link
Member

pyricau commented May 21, 2024

Thanks for filing. This looks awfully similar to #2314, and I believe it's actually the same bug, caused by a revert of the fix on the Google side.

At the time, the fix was implemented in Lifecycle 2.5.0-rc02: https://android-review.googlesource.com/c/platform/frameworks/support/+/2108693/1/lifecycle/lifecycle-viewmodel/src/main/java/androidx/lifecycle/ViewModelProvider.kt#189

The key part was the addition of a try catch ("AGP has some desugaring issues associated with compileOnly dependencies")

image

In February, this change landed, migrating the code to KMP and seemingly not backporting the fix: https://android-review.googlesource.com/c/platform/frameworks/support/+/2966765/18/lifecycle/lifecycle-viewmodel/src/androidMain/kotlin/androidx/lifecycle/ViewModelProvider.android.kt#b179

image

@pyricau
Copy link
Member

pyricau commented May 21, 2024

Filed https://issuetracker.google.com/issues/341792251

@msasikanth
Copy link

I am having the same issue, but the crash didn't happen for me on Android 14, but when I tried it with older versions it crashed.

@vullnetlimani
Copy link

The same issue hopefully they fix it as well I am going to comment on the issue as well ...

Was thinking first what's going on till I got it 😅 and than landed here, after searching the problem!

@pyricau
Copy link
Member

pyricau commented May 30, 2024

Fixed here, not sure when that'll get released: https://android-review.googlesource.com/c/platform/frameworks/support/+/3096018

lifecycle 2.8.1 was just released today, so hopefully this goes into next release... in 2 weeks?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants