Write the ProGuard keep rule to fix reflection after R8

This tests R8 dead-code removal and exact ProGuard syntax for reflective constructors. A strong answer gives -keep class com.example.T { <init>(...); } because R8 cannot trace dynamic class names. Broad -keep rules or omitting constructor are red flags.
This tests deep knowledge of R8 static analysis limits and the ProGuard keep rule grammar for reflection. A strong answer writes -keep class com.example.Target { <init>(...); }, explains that R8 cannot follow string constants into Class.forName or newInstance calls, and therefore strips or renames the unused class. Mentioning -keepclassmembers as an alternative for the constructor is a plus. A red flag is suggesting -keep class * or relying solely on keepattributes without pinning the specific class and constructor.
Read the original → developer.android.com
- #android
- #r8
- #proguard
- #reflection
- #build-optimization
Get five bites like this every day.
Tezvyn delivers a daily feed of 60-second tech bites with quizzes to lock in what you learn.