Prevent Proguard from removing empty constructor of fragment

Wayne picture Wayne · Nov 30, 2012 · Viewed 9.6k times · Source

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
}

Answer

Snicolas picture Snicolas · Nov 30, 2012

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.