I'm using Proguard to obfuscate a library that has several @Autowired fields. The obfuscator is renaming those class fields (because they are private/internal to the class) and thus my bean is failing to instantiate.
Pre-obfuscated:
@Service
public class LicenseServiceImpl implements LicenseService {
@Autowired(required = false)
LicenseSessionStore licenseSessionStore;
@Autowired(required = false)
LicenseStore licenseStore;
...
}
Post-obfuscation:
@Service
public class LicenseServiceImpl implements LicenseService {
@Autowired(required=false)
LicenseSessionStore a;
@Autowired(required=false)
LicenseStore b;
...
}
Now there are likely a lot of ways to make these particular fields not get autowired but what I was hoping to find was a way to tell Proguard to not obfuscate any internal fields that are annotated with important Spring-isms (@Autowired, etc.).
Anyone have an idea on how I can generically do this?
Grant
By default, ProGuard obfuscates the code: it assigns new short random names to classes and class members. It removes internal attributes that are only useful for debugging, such as source files names, variable names, and line numbers.
The @Autowired annotation can be used to autowire bean on the setter method just like @Required annotation, constructor, a property or methods with arbitrary names and/or multiple arguments.
Enabling @Autowired AnnotationsThe Spring framework enables automatic dependency injection. In other words, by declaring all the bean dependencies in a Spring configuration file, Spring container can autowire relationships between collaborating beans. This is called Spring bean autowiring.
I had a similar problem retaining class names for simplexml annotated classes. My fix was to add the following:
-keepclassmembers class * {
@org.simpleframework.xml.* *;
}
I think something similar would work for you:
-keepclassmembers class * {
@org.springframework.beans.factory.annotation.* *;
}
I do not consider this a correct answer to my question and would still like an elegant, generic solution to this problem. What I'm posting is my temporary workaround which got me past my issue in the most brute force, inelegant way.
I explicitly excluded these items from obfuscation by adding them into a keepclassmembernames option:
<option>-keepclassmembernames class * {com.common.license.LicenseSessionStore licenseSessionStore; com.common.license.LicenseStore licenseStore; }</option>
This is not a preferred solution as it requires specific named overriding in each and every class and will become a maintenance nightmare.
A better answer is still needed!
Grant
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