proguard

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/bawang_cn/article/details/69666057
后面慢慢修改,先贴出来
-optimizationpasses 5                                                           # 指定代码的压缩级别
#-dontusemixedcaseclassnames                                                     # 是否使用大小写混合
-dontskipnonpubliclibraryclasses                                                # 是否混淆第三方jar
#-dontpreverify                                                                  # 混淆时是否做预校验
#-keepattributes SourceFile,LineNumberTable,InnerAnonymousClass                                   # 混淆号错误信息里带上代码行
-verbose                                                                        # 混淆时是否记录日志
-keepattributes SourceFile,LineNumberTable,AnonymousClass ,Exceptions,InnerClasses,Signature,Deprecated,SourceFile,LineNumberTable,Annotation,EnclosingMethod,RuntimeInvisibleTypeAnnotations
#-optimizations !code/simplification/arithmetic,!field/*,!class/merging/*        # 混淆时所采用的算法
#-keepattributes Exceptions,InnerClasses,Signature,Deprecated,SourceFile,*Annotation*,Synthetic,EnclosingMethod,JavascriptInterface

#-repackageclasses ''
#-allowaccessmodification
#-dontwarn
-dontshrink
-dontoptimize

-dontwarn com.bde.parentcytransport.*
-keep  class com.bde.parentcytransport.BleUtility{*;}
-keep  class com.bde.parentcytransport.BleUtility$* {
    *;
}
#-keepclasseswithmembers  class com.bde.parentcytransport.ACSUtilityService { *; }
#-dontwarn com.bde.parentcytransport.ACSUtilityService
-keep  class com.bde.parentcytransport.ACSUtilityService{
  *;
}
-keep  class com.bde.parentcytransport.ACSUtilityService$* {
    *;
}
# public  android.bluetooth.BluetoothGattCallback mGattCallback;


# keep 4大组件, application
-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.os.Binder




#-keep public class  com.bde.parentcytransport.ACSUtilityService
#-keep public class com.bde.parentcytransport.ACSUtilityService{
#   *;
#}
#-keep public class com.bde.parentcytransport.ACSUtilityService$* {
#   public *;
#}
#-keepnames class * implements android.bluetooth.BluetoothGattCallback
#-keepclassmembers class com.bde.parentcytransport.BleUtility$* {
#    *;
#}
#-keepnames  class com.bde.parentcytransport.BleUtility$* {
#    public <fields>;
#    public <methods>;
#}
#-keep class com.bde.parentcytransport.BleUtility$IBleUtilityCallback {
#    *;
#}
#-keep class com.bde.parentcytransport.BleUtility$ICardCallback {
#    *;
#}
#-dontwarn com.bde.parentcytransport.BleUtility
#-keep interface  com.bde.parentcyTransport.BleUtility.ICardCallback
#-keep interface  com.bde.parentcyTransport.BleUtility.IBleUtilityCallback
#-keep class com.bde.parentcytransport.BleUtility.**{*;}
#-keepnames com.bde.parentcytransport.BleUtility$* {
#    public <fields>;
#    public <methods>;
#}
#-keep interface * com.bde.parentcyTransport.BleUtility.ICardCallback
#-keep interface * com.bde.parentcyTransport.BleUtility.IBleUtilityCallback
#-keep interface com.bde.parentcyTransport.BleUtility$ICardCallback {
#    public <methods>;
#}
#
#-keep interface com.bde.parentcyTransport.BleUtility$IBleUtilityCallback {
#    public <methods>;
#}

-dontwarn com.bde.parentcytransport.*

    # 自定义的view类
    -keep public class * extends android.view.View {
        public <init>(android.content.Context);
        public <init>(android.content.Context, android.util.AttributeSet);
        public <init>(android.content.Context, android.util.AttributeSet, int);
        public void set*(...);
    }
    #To maintain custom components names that are used on layouts XML:
    -keep public class * extends android.view.View {
        public <init>(android.content.Context);
    }
    -keep public class * extends android.view.View {
        public <init>(android.content.Context, android.util.AttributeSet);
    }
    -keep public class * extends android.view.View {
        public <init>(android.content.Context, android.util.AttributeSet, int);
    }

    # Serializables类
    -keepnames class * implements java.io.Serializable
    -keepclassmembers class * implements java.io.Serializable {
        static final long serialVersionUID;
        private static final java.io.ObjectStreamField[] serialPersistentFields;
        !static !transient <fields>;
        !private <fields>;
        !private <methods>;
        private void writeObject(java.io.ObjectOutputStream);
        private void readObject(java.io.ObjectInputStream);
        java.lang.Object writeReplace();
        java.lang.Object readResolve();
    }


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



    # keep 类成员
    -keepclasseswithmembers class * {
        public <init>(android.content.Context, android.util.AttributeSet);
    }
    -keepclasseswithmembers class * {
        public <init>(android.content.Context, android.util.AttributeSet, int);
    }

    # keep parcelable
    -keepclassmembers class * implements android.os.Parcelable {
        static android.os.Parcelable$Creator CREATOR;
    }

    #Keep the R
    -keepclassmembers class **.R$* {
        public static <fields>;
    }

    -keepclassmembers public class * extends android.view.View {
      void set*(***);
      *** get*();
    }

    #Maintain java native methods
    -keepclasseswithmembernames class * {
        native <methods>;
    }

    #Maintain enums
    -keepclassmembers enum * {
        public static **[] values();
        public static ** valueOf(java.lang.String);
    }

    # Remove Logging
    -assumenosideeffects class android.util.Log {
        public static *** d(...);
        public static *** w(...);
        public static *** v(...);
        public static *** i(...);
    }

    -ignorewarnings

混淆会遇到很多小问题,需要理解含义,这里先贴一个网址供参考:

https://www.guardsquare.com/en/proguard/manual/attributes


下面做个简单的说明:

不混淆一个类:

-keep  class com.xxx.xxx.Name { *; }
Name指的是类名。
就这么一句话搞定

不混淆一个类,并且也不混淆内部类,匿名内部类等:
-keep  class com.xxx.xxx.Name { *; }
-keep  class com.xxx.xxx.Name$* { *; }

不要在class前面加public,那样匿名内部类就会出问题,也会被混淆。

如果一个包混淆了其余的,保留了某几个类 ,就找上面的写法依次写完,然后在前面加一句
-dontwarn com.xxx.xxx.**


但是在pro文件前面不要忘记这句:
-keepattributes Exceptions,InnerClasses,Signature,Deprecated,SourceFile,*Annotation*,Synthetic,EnclosingMethod,JavascriptInterface
具体参数可以修改,根据自己的情况作出合适的修改,具体参考上面的网址链接





阅读更多
想对作者说点什么?

博主推荐

换一批

没有更多推荐了,返回首页