proguard

后面慢慢修改,先贴出来
-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
具体参数可以修改,根据自己的情况作出合适的修改,具体参考上面的网址链接





评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值