Closed abd3lraouf closed 2 years ago
This sounds like an R8 optimization issue, similar to https://github.com/google/dagger/issues/2291#issuecomment-772096011.
Can you tell us more about your proguard / r8 configuration. It would be helpful too if you shared some of reports as mentioned here: https://developer.android.com/studio/build/shrink-code#troubleshoot
Noticed this was reported not so long ago too: https://github.com/google/dagger/issues/2226.
They had a non-public EntryPoint which I think you also have. Maybe we should report this to the R8 team, as it might be an interface merging issue.
Thank you @danysantiago for your response, really appreciate your help.
Actually was working on a side project trying to reproduce the issue for you and nearly found it.
The main issue is that hilt cannot work with libraries in release mode, meaning I cannot generate a release aar build (minification enabled) as it needs an application that will be provided later by library users.
I'm just curious if there is something else we can do about it.
@danysantiago I've created the application to reproduce the issue
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.
R8 is failing on a release build and working normally on debug.
and After Decompiling the application found out that
DemoApplication_HiltComponents$SingletonC
doesn't implement theHiltWrapper_CustomEntryPoint
class it's removed completely from the class signature. And it does appear on debug builds.