Wayne
Wayne

Reputation: 6449

Prevent Proguard from removing empty constructor of fragment

You know, all subclasses of Fragment must include a public empty constructor but when using proguard these constructors will be removed. I have specified below commands but empty constructor still be removed. Can anyone help me to keep empty constructor of Fragment? Thanks you.

-keepclassmembers public class * extends android.support.v4.app.Fragment { 
   public <init>(***);
   #public <init>(); //already tried this
}

-keepclassmembers public class * extends com.xxx.MyFragment { 
   public <init>(***);
   #public <init>(); //already tried this
}

Upvotes: 34

Views: 13798

Answers (1)

Snicolas
Snicolas

Reputation: 38168

This should work :

-keepclassmembers public class * extends android.support.v4.app.Fragment { 
   public <init>(...);

I believe even this should be enough :

-keep public class * extends android.support.v4.app.Fragment

as keeping the class will oblige proguard to keep the default constructor.

Upvotes: 55

Related Questions