Open
Description
After updating both AGP to 8.9.2 and Hilt to 2.56.2, my app crashes in release builds due to a NoSuchMethodException when trying to create a @hiltviewmodel instance. The constructor appears to be stripped by R8.
Interestingly, this crash does not occur if I update only Hilt to 2.56.2, I found that this commit removed the keep rule:
-keepnames @dagger.hilt.android.lifecycle.HiltViewModel class * extends androidx.lifecycle.ViewModel
When I re-added this rule manually to my proguard-rules.pro, the crash was resolved.
Caused by: java.lang.NoSuchMethodException: <init> []
Caused by: java.lang.RuntimeException: Cannot create an instance of class x.x.x.MyViewModel
at dagger.hilt.android.internal.lifecycle.HiltViewModelFactory.create(SourceFile:18)
Steps to Reproduce:
- Use Hilt 2.56.1 + AGP 8.9.2
- Create a simple @hiltviewmodel class with an injected constructor
- Inject it in an @androidentrypoint activity using by viewModels()
- Enable minification (minifyEnabled true) in release build
- Build and run → crash on launch
Metadata
Metadata
Assignees
Labels
No labels