Skip to content

Commit 24c5002

Browse files
committed
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
1 parent 445e6f0 commit 24c5002

2 files changed

Lines changed: 12 additions & 2 deletions

File tree

hilt-android/main/resources/META-INF/com.android.tools/proguard/hilt-android.pro

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,9 @@
22
# See b/183070411#comment4 for more info.
33
-keep,allowobfuscation,allowshrinking @dagger.hilt.internal.ComponentEntryPoint class *
44
-keep,allowobfuscation,allowshrinking @dagger.hilt.internal.GeneratedEntryPoint class *
5-
-keep,allowobfuscation,allowshrinking @dagger.hilt.android.EarlyEntryPoint class *
5+
-keep,allowobfuscation,allowshrinking @dagger.hilt.android.EarlyEntryPoint class *
6+
7+
# Prevent R8 full mode from vertically merging Hilt_* base classes with
8+
# @AndroidEntryPoint user classes. The bytecode transform rewrites user classes
9+
# to extend Hilt_*; vertical class merging breaks this hierarchy.
10+
-keep,allowobfuscation,allowshrinking class **.Hilt_*

hilt-android/main/resources/META-INF/com.android.tools/r8/hilt-android.pro

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,9 @@
22
# See b/183070411#comment4 for more info.
33
-keep,allowobfuscation,allowshrinking @dagger.hilt.internal.ComponentEntryPoint class *
44
-keep,allowobfuscation,allowshrinking @dagger.hilt.internal.GeneratedEntryPoint class *
5-
-keep,allowobfuscation,allowshrinking @dagger.hilt.android.EarlyEntryPoint class *
5+
-keep,allowobfuscation,allowshrinking @dagger.hilt.android.EarlyEntryPoint class *
6+
7+
# Prevent R8 full mode from vertically merging Hilt_* base classes with
8+
# @AndroidEntryPoint user classes. The bytecode transform rewrites user classes
9+
# to extend Hilt_*; vertical class merging breaks this hierarchy.
10+
-keep,allowobfuscation,allowshrinking class **.Hilt_*

0 commit comments

Comments
 (0)