How to create an obfuscated jar file?

后端 未结 5 962
故里飘歌
故里飘歌 2021-02-02 03:23

How can I go about creating an obfuscate jar file? As of now I can easily export my Android lib project to a jar and use it. How do I obfuscate the jar file?

My end goa

5条回答
  •  灰色年华
    2021-02-02 03:40

    you to enable proguard for your project - its very easy. http://developer.android.com/guide/developing/tools/proguard.html

    one common error that can occur is that methods aren't found when using reflection. This is because the obfuscation removes method names and sometimes even whole classes. If you have custom views the same thing can happen.

    You configure what classes to keep by using the "-keep" flag in proguard.cfg

    here are some common ones this is from a maven build - but the concept is the same

    -keep public class * extends android.app.Activity
    -keep public class * extends android.app.Application
    -keep public class * extends android.app.Service
    -keep public class * extends android.content.BroadcastReceiver
    -keep public class * extends android.content.ContentProvider
    -keep public class * extends android.view.View {
                                    public (android.content.Context);
                                    public (android.content.Context, android.util.AttributeSet);
                                    public (android.content.Context, android.util.AttributeSet, int);
                                    public void set*(...);  
    -keepclasseswithmembers class * {
                                    public  (android.content.Context, android.util.AttributeSet); } 
    -keepclasseswithmembers class * {
                                    public  (android.content.Context, android.util.AttributeSet, int); } 
    -keepclassmembers class * implements android.os.Parcelable {
                                    static android.os.Parcelable$Creator *; }
    -keepclassmembers class **.R$* { public static ; } 
    -keepclasseswithmembernames class * { native ; } 
    -keepclassmembers class * extends java.lang.Enum {
                                    public static **[] values();
                                    public static ** valueOf(java.lang.String); }
    -keepclassmembers class * extends android.app.Activity{
                                    public void *(android.view.View); } 
    

    quite a big area, but hope it helps ...

提交回复
热议问题