Domanda

I have methods that are used by Android framework ObjectAnimator instances. Hence they appear to be unused (they are used through reflection) and I add SuppressWarnings("unused") annotation, so IntelliJ don't show warnings for them. However, ProGuard still strips them and I need to explicitly tell him not to. This is tedious and seems redundant (violates DRY). Is it possible to configure ProGuard not to remove methods with SuppressWarnings("unused")?

È stato utile?

Soluzione

Options that tell ProGuard to keep some classes and members (fields and methods) are described in the official documentation: http://proguard.sourceforge.net/manual/usage.html#keepoptions.

You can tell ProGuard to preserve class members using:

-keepclassmembers class_specification

Your class_specification will look like:

class * {
    @java.lang.SuppressWarnings <methods>;
}

So, in your proguard.cfg you should have something like this:

-keepclassmembers class * {
    @java.lang.SuppressWarnings <methods>;
}

Altri suggerimenti

Sorry to poke a dead thread but I recently ran into this and discovered it is not possible. Because SuppressWarnings has SOURCE level retention it is not in the class file processed by Proguard (as covered in this SO post). I ended up using android support's @Keep annotation instead and configuring it with a rule similar to Adam's:

-keepclassmembers class * {
  @proguard.annotation.Keep <methods>;
}

I've faced similar stripping problem with Dexguard. I've solved in a really dirty way, placing this somewhere:

if(System.currentTimeMillis() < 0 ){ //never happens
   //..
   //TODO directly invoke stripped methods
   //..
}
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top