Question

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

Was it helpful?

Solution 2

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

OTHER TIPS

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.* *;
} 
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top