Reputation: 652
After updating Android Studio to the new release (Jellyfish) and updating the Android Gradle Plugin to 8.4, my release builds are failing with a slew of issues related to things injected with daggar/hilt. I spent the afternoon adding keep rules for everything that's being injected, and ended up an error saying I need a @Provides rule for CoroutineScope, which I could not manage to resolve.
Can anyone give me a concise set of rules for Daggar/Hilt and AGP 8.4?
This project is multi-module project. I was also running into issues with name clashes (two modules mapping different classes to a.a). To solve that I putting:
repackageclasses 'x'
with a different value for x for each module.
In the end, I reverted AGP. But long term, I'll need to figure out a solution (or hopefully updates will fix it).
Upvotes: 15
Views: 2818
Reputation: 4270
If you have enabled isMinifyEnabled = true
in library modules then library module will minify it-self before providing aar file to app or any other module.
It means that library will be minified without knowing that which classes are used by other modules (Everything will be minified except some keep rules).
Link to official documentation which might help you understand the changes: Library classes are shrunk
Use isMinifyEnabled = false
in library modules and add consumerProguardFiles("consumer-rules.pro")
to tell app module what to keep, leave it empty if no special case.
Above changes will let app module can minify all codes including your library module codes during proguard process.
After this changes we can now update AGP to 8.4.1 and gradle wrapper to 8.6 without any hilt or proguard issues.
This is how I fixed mine issue. Still if you have any issues please let us know in the comment. It should be fixable by updating proguard rules.
Note: This answer applies to multi-module projects and not to libraries which are getting published somewhere like maven because they might want to minify their library before publishing.
Upvotes: 11
Reputation: 31
This issue has been burning me for the last few days. The problem I'm facing is a bug in the implementation of this feature. We have a project library that we want to minify (because it gets shipped to other companies). We also have local tests for it. The local tests do not want to use a minified build, because they are testing individual internals. With jUnit, the classes are located by name, so obfuscation breaks it. If we add the keep rules, then the shipping AAR ends up with classes that should be obfuscated, but aren't. If we don't add the keep rules, the test harness kicks off with a minified release build and can't find the internal classes. The options I'm seeing are to either run all the test cases as debug or create a new build type for tests. Despite Google providing a beautiful way to integrate tests into the product, it appears this is a weakness in AGP 8.4+.
Upvotes: 3