From 24c50020b145321787e26bacc6442dd981130812 Mon Sep 17 00:00:00 2001 From: Senthil Raja R Date: Tue, 16 Jun 2026 11:07:16 +0530 Subject: [PATCH] Add R8 keep rule for Hilt_* base classes to fix ClassCastException in release builds Use -keep,allowobfuscation,allowshrinking instead of bare -keep so that R8 can still rename and remove unused Hilt_* classes while preventing vertical class merging that breaks the bytecode-transformed hierarchy. Fixes #4668 --- .../META-INF/com.android.tools/proguard/hilt-android.pro | 7 ++++++- .../META-INF/com.android.tools/r8/hilt-android.pro | 7 ++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/hilt-android/main/resources/META-INF/com.android.tools/proguard/hilt-android.pro b/hilt-android/main/resources/META-INF/com.android.tools/proguard/hilt-android.pro index 4e8b7f3c40b..cf9d5d6712f 100644 --- a/hilt-android/main/resources/META-INF/com.android.tools/proguard/hilt-android.pro +++ b/hilt-android/main/resources/META-INF/com.android.tools/proguard/hilt-android.pro @@ -2,4 +2,9 @@ # See b/183070411#comment4 for more info. -keep,allowobfuscation,allowshrinking @dagger.hilt.internal.ComponentEntryPoint class * -keep,allowobfuscation,allowshrinking @dagger.hilt.internal.GeneratedEntryPoint class * --keep,allowobfuscation,allowshrinking @dagger.hilt.android.EarlyEntryPoint class * \ No newline at end of file +-keep,allowobfuscation,allowshrinking @dagger.hilt.android.EarlyEntryPoint class * + +# Prevent R8 full mode from vertically merging Hilt_* base classes with +# @AndroidEntryPoint user classes. The bytecode transform rewrites user classes +# to extend Hilt_*; vertical class merging breaks this hierarchy. +-keep,allowobfuscation,allowshrinking class **.Hilt_* \ No newline at end of file diff --git a/hilt-android/main/resources/META-INF/com.android.tools/r8/hilt-android.pro b/hilt-android/main/resources/META-INF/com.android.tools/r8/hilt-android.pro index 4e8b7f3c40b..cf9d5d6712f 100644 --- a/hilt-android/main/resources/META-INF/com.android.tools/r8/hilt-android.pro +++ b/hilt-android/main/resources/META-INF/com.android.tools/r8/hilt-android.pro @@ -2,4 +2,9 @@ # See b/183070411#comment4 for more info. -keep,allowobfuscation,allowshrinking @dagger.hilt.internal.ComponentEntryPoint class * -keep,allowobfuscation,allowshrinking @dagger.hilt.internal.GeneratedEntryPoint class * --keep,allowobfuscation,allowshrinking @dagger.hilt.android.EarlyEntryPoint class * \ No newline at end of file +-keep,allowobfuscation,allowshrinking @dagger.hilt.android.EarlyEntryPoint class * + +# Prevent R8 full mode from vertically merging Hilt_* base classes with +# @AndroidEntryPoint user classes. The bytecode transform rewrites user classes +# to extend Hilt_*; vertical class merging breaks this hierarchy. +-keep,allowobfuscation,allowshrinking class **.Hilt_* \ No newline at end of file