Genjuro
Genjuro

Reputation: 7735

how to keep a class that extends and implements an interface with Proguard

i need to keep all class that extend com.opensymphony.xwork2.ActionSupport and implements a custom interface .

when i try this

-keepnames public class * extends com.opensymphony.xwork2.ActionSupport implements com.company.project.utils.Constantes {
 *; 
 }

i get the following error :

error expecting openning '{' at 'implements'

Upvotes: 2

Views: 6067

Answers (1)

vaughandroid
vaughandroid

Reputation: 4374

If memory serves, you can specify classes that extend another class OR classes that implement an interface, but not both. The documentation doesn't make this particularly clear but it is implied there.

There are a couple ways around this, assuming that it isn't sufficient for you to just specify one or the other:

  • Create an empty 'marker' interface and have the classes you want to keep extend that.
  • Add a static (can be private static final if you like) marker field to each of the classes you want to keep, and specify that in the -keep options.
  • Bite the bullet and just list the names of all the classes you want to keep.

EDIT

Another option would be to create a class like this:

public abstract class Foo extends com.opensymphony.xwork2.ActionSupport implements com.company.project.utils.Constantes {
    // ...
}

Then, have all the classes you want to keep extend that class. Then you just need to specify * extends Foo in the -keep options.

Upvotes: 4

Related Questions