Skip to content

Crash in release build after updating to AGP 8.9.2 + Hilt 2.56.2: @HiltViewModel constructor stripped #4739

Open

Description

@javadjafari1

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:

  1. Use Hilt 2.56.1 + AGP 8.9.2
  2. Create a simple @hiltviewmodel class with an injected constructor
  3. Inject it in an @androidentrypoint activity using by viewModels()
  4. Enable minification (minifyEnabled true) in release build
  5. Build and run → crash on launch

Activity

  1. changed the title [-]Crash in release build after updating to AGP 8.9.2 + Hilt 2.56.1: @HiltViewModel constructor stripped[/-] [+]Crash in release build after updating to AGP 8.9.2 + Hilt 2.56.2: @HiltViewModel constructor stripped[/+] on May 27, 2025
  2. Chang-Eric commented on Jun 10, 2025

    @Chang-Eric
    Member

    Interestingly, this crash does not occur if I update only Hilt to 2.56.2

    Just to clarify, are you saying that you can make this crash occur just by upgrading AGP to 8.9.2? Or is it only the combination of upgrading Hilt and AGP that causes the crash? Also, what is the previous version of AGP you are using?

  3. 530l commented on Jan 2, 2026

    @530l

    Use Hilt 2.57.1 +KSP + AGP 8.9.1 也会出现,增加了-keepnames @dagger.hilt.android.lifecycle.HiltViewModel class * extends androidx.lifecycle.ViewModel 混淆规则就不崩溃了

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions