I want to skip a particular class from deletion. It isn't normally referenced anywhere in my application, but only by reflection, therefore it does get removed by the shrinker. It is referenced by other "adjacent" classes in its package, but yet, not used for my application directly, but only by reflection.
I decided to treat specifically for this particular class, a mapping:
org.mypckg.Helper -> gh6
...then ofcourse I changed the reflection call withing my app:
forName("gh6")
There seems to be no problem with my mapping input, but the mapping rule itself is not enough to prevent the class from removal. In addition I still cannot keep the class using the -keep switches, because it does preserve it using its original name (org.mypckg.Helper), which I don't want.
For one reason or another, I cannot manually refractor(rename) the class to 'gh6' within the project.
ProGuard recognizes the construct Class.forName("org.mypckg.Helper")
; it then keeps and obfuscates org.mypckg.Helper
without further configuration.
Otherwise:
-keep,allowobfuscation class org.mypckg.Helper
-adaptclassstrings org.mypckg.AdjacentClass*
Cfr. ProGuard manual > Usage > Overview of Keep Options
Cfr. ProGuard manual > Usage > -adaptclassstrings
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With