Alex Rivera | Logout

Prevent Proguard from removing empty constructor of fragment

Asked 2012-11-30T06:35:41.107
35

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
}
Edit
Report

1 Answer

55

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.

answered 2012-11-30T06:39:35.063

Your Answer