R8 - ClassCastException because of removed EntryPoint HiltWrapper_ classes
See original GitHub issueR8 is failing on a release build and working normally on debug.
Caused by: java.lang.ClassCastException: Cannot cast somepackage.DaggerDemoApplication_HiltComponents_SingletonC to somepackage.r.f
...
at dagger.hilt.android.EntryPointAccessors.fromApplication(EntryPointAccessors.java:35)
at somepackage.someclass.onCreate(someclass.java:1)
EntryPointAccessors.fromApplication(
context.applicationContext,
CustomEntryPoint::class.java
)
and After Decompiling the application found out that DemoApplication_HiltComponents$SingletonC
doesn’t implement the HiltWrapper_CustomEntryPoint
class it’s removed completely from the class signature. And it does appear on debug builds.
Issue Analytics
- State:
- Created a year ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
ClassCastException after obfuscation internal classes with ...
Now the true weird problem is that the ClassCastException disappears as soon as I remove the suspend modifier. I tried adding - ...
Read more >R8 FAQ
So if instances of a given class are only created through deserialization from JSON, R8 will not see that class as instantiated leaving...
Read more >ClassCastException after updating to R8 2.0.59 (Android ...
After updating the Android Gradle plugin from version 3.6.2 to 4.0.0-beta04 I get a ClassCastException in a release build:
Read more >ProGuard Troubleshooting
Possibly, some class file didn't get recompiled properly, or some class file was left behind after its source file was removed. Try removing...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Thanks for the repro!
The issue is not with Hilt itself but just with the nature of minification, by shrinking a library and not the final APK you need to add rules to keep your public APIs since from R8’s perspective, many classes, including the SDK APIs are not used and will get removed. I see the project already has a rule for classes in your package but with code generating libraries like Dagger and Hilt you need to also consider the generated classes and specifically keep those too.
Hilt for example, generates various metadata classes in a special package called
hilt_aggregated_deps
, which is used to pass information across compilations and get aggregated into the ‘root’ where Dagger components are generated. So in order to create a consumable SDK that uses Hilt and is minified, you’ll need to add a rules for the generated classes:-keep class hilt_aggregated_deps.** { *; }
.Note that this is a general trade-off when minifying or obfuscating a library, you need to verify the produced library has its public API as desired, including generated code, where as if R8 is run in the app, then it can figure out what is being used from the app and remove unnecessary code, including code from consumed libraries.
@danysantiago I’ve created the application to reproduce the issue
https://github.com/abd3lraouf/DaggerReleaseIssue