-
Notifications
You must be signed in to change notification settings - Fork 4k
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
LeakCanary crashing app on start: java.lang.AbstractMethodError: androidx.lifecycle.ViewModel #2314
Comments
Same thing is happening for me also. |
Basically lifecycle-2.5.0-alpha01 added a new preferred create() method to ViewModelProvider.Factory that takes an additional CreationExtras parameter. LeakCanary's ViewModelClearedWatcher Line 47 in 79cdab7
Haven't had any time to test either fix, so I might be way off in left field. |
Interesting. Any suggested fix from the LeakCanary side? I worry that updating the dependency version might trigger the same crash for users of older versions of the lib. Also, can you provide a sample project for repro? |
So I first verified that adding that method to ViewModelClearedWatcher does solve this issue for me and I'll be using that as a temporary measure. I then spent way too much time trying to create a simple repro before realizing the trigger is the minsdk. Anything under API 24 will cause the crash. So it somehow ties into the Java 8, desugaring, and Kotlin interface default methods. Note: You need to install the final debug version of the app. Launching it from Studio will install the APK from app\build\intermediates\apk\debug\app-debug.apk which doesn't crash, but the version after doing a Make Project from app\build\outputs\apk\debug\app-debug.apk will. I don't really see an easy and clean way of fixing this on LeakCanary side. Looks to be a bug in the gradle plugin side. Possibly a separate module that can be manually specified? Not an area that I'm too familiar with. |
Thanks for the super detailed answer and the repro! |
Since lifecycle 2.5.0 is still in alpha, we should probably see if this is a known issue / if the alphas can be fixed. |
@dougnazar do you think you could file an issue on the Lifecycle project? |
Seeme like this is caused by a missing dependency on |
I believe this is on purpose. LeakCanary seems to go out of its way to not pull in dependencies that might not be used/wanted. Which was great until this issue popped up. I'm currently thinking of changing the compileOnly to implementation but removing the androidx module from android-core. Trade off is that it won't pull in androidx automatically but you'd need to specify an additional module if you use androidx. Not sure which is preferred, or if the LeakCanary devs have a better option. |
So this seems to be working for me:
and then adding the following to my projects:
|
This is absolutely not the right fix. LeakCanary should not declare an explicit dependency on lifecycle, the whole point of it being optional is that consumers can leverage whichever version they like or even not have that dependency and everything will work just fine. Lifecycle just broke backward compatibility. |
Lifecycle 2.5.0-rc02 will include a fix for this: https://android-review.googlesource.com/c/platform/frameworks/support/+/2108693 |
Closing as this is fixed on the lifecycle side. |
Long story short:
Example
Where |
Description
Hello in our app we use LeakCanary library. We have recently upgraded gradle, kotlin gradle scripts to KTS, etc. Now when we build APK through Android Studio by "Generate Signed APK" or "Generate APKs" or in terminal by "gradlew assembleSomethingDebug" as Debug type it causing crash on start app.
Once I remove the LeakCanary library from debugImplementation in build.gradle.kts. It will stop crashing.
Log:
Version Information
The text was updated successfully, but these errors were encountered: