Java ProGuard. Keep class (not delete), but still allow to be confused

I want to skip a specific class from deletion. This is usually not mentioned anywhere in my application, but only by reflection, so it is removed using shrinkage. It refers to other "adjacent" classes in its package, but is still not used directly for my application, but only by reflection.

I decided to specifically consider this class, mapping:

org.mypckg.Helper -> gh6 

... then, of course, I changed the reflection call with my application:

 forName("gh6") 

There seems to be no problem with my display input, but the display rule itself is not enough to prevent the class from being deleted. Also, I still cannot save the class using the -keep switches, because it saves it using its original name (org.mypckg.Helper), which I don't want.

For one reason or another, I cannot manually refract (rename) the class to "gh6" in the project.

+4
source share
1 answer

ProGuard recognizes the Class.forName("org.mypckg.Helper") construct Class.forName("org.mypckg.Helper") ; it then saves and obfuscates org.mypckg.Helper without additional configuration.

Otherwise:

 -keep,allowobfuscation class org.mypckg.Helper -adaptclassstrings org.mypckg.AdjacentClass* 

CFR. ProGuard Handbook> Usage> Overview of Save Options

CFR. ProGuard Handbook> Usage> - adaptclassstrings

+5
source

Source: https://habr.com/ru/post/1435907/


All Articles