Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 } 
like image 670
Wayne Avatar asked Nov 30 '12 06:11

Wayne


People also ask

What is ProGuard obfuscation?

You can obfuscate Android code to provide security against reverse engineering. You can use the Android ProGuard tool to obfuscate, shrink, and optimize your code. Obfuscated code can be more difficult for other people to reverse engineer.

What is R8 ProGuard?

R8 is another tool that will convert your java byte code into an optimized format of dex code. It will check the whole application and will remove the unused classes and methods. It helps us to reduce the size of our APK and to make our app more secure. R8 uses similar proguard rules to modify its default behavior.

What is keep in ProGuard?

-keep disables all of ProGuard's goodness. No shrinking, no obfuscation; not for classes, not for members. In real use cases, you can let ProGuard do at least some of it's work.


1 Answers

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.

like image 118
Snicolas Avatar answered Sep 28 '22 04:09

Snicolas