# Add project specific ProGuard rules here. # You can control the set of applied configuration files using the # proguardFiles setting in build.gradle. # # For more details, see # http://developer.android.com/guide/developing/tools/proguard.html # If your project uses WebView with JS, uncomment the following # and specify the fully qualified class name to the JavaScript interface # class: #-keepclassmembers class fqcn.of.javascript.interface.for.webview { # public *; #} # Uncomment this to preserve the line number information for # debugging stack traces. #-keepattributes SourceFile,LineNumberTable # If you keep the line number information, uncomment this to # hide the original source file name. #-renamesourcefileattribute SourceFile # 默认的混淆文件 C:\0Develop\AndroidSDK\tools\proguard\proguard-android-optimize.txt # 不应移除代码: # 当应用通过 Java 原生接口 (JNI) 调用方法时 # 当您的应用在运行时查询代码时(如使用反射) # 动态生成的字符串查询资源名称时(如R.drawable.img_%1d) #不警告 -dontwarn #保持自定义控件类不被混淆 -keepclasseswithmembers class * { public (android.content.Context, android.util.AttributeSet); } -keepclasseswithmembers class * { public (android.content.Context, android.util.AttributeSet, int); } #保持 Serializable 不被混淆 -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 ; !private ; !private ; private void writeObject(java.io.ObjectOutputStream); private void readObject(java.io.ObjectInputStream); java.lang.Object writeReplace(); java.lang.Object readResolve(); } #移除Log类打印各个等级日志的代码,打正式包的时候可以做为禁log使用,这里可以作为禁止log打印的功能使用,另外的一种实现方案是通过BuildConfig.DEBUG的变量来控制 -assumenosideeffects class android.util.Log { public static *** v(...); public static *** i(...); public static *** d(...); public static *** w(...); public static *** e(...); } # WebView使用javascript功能则需要开启 -keepclassmembers class fqcn.of.javascript.interface.for.webview { public *; } #######################项目独有文件################################# # 如果使用了Gson之类的工具要使被它解析的JavaBean类即实体类不被混淆。 -keep class com.hqumath.map.bean.**{*;} #SDK需要引用导入工程的资源文件,通过了反射机制得到资源引用文件R.java,但是在开发者通过proguard等混淆/优化工具处理apk时,proguard可能会将R.java删除,如果遇到这个问题,请添加如下配置: TODO -keep public class com.hqumath.map.R$*{ public static final int *; } #######################第三方模块################################### # opengl -keep public class android.opengl.** {*;} # glide -keep public class * implements com.bumptech.glide.module.GlideModule -keep public enum com.bumptech.glide.load.resource.bitmap.ImageHeaderParser$** { **[] $VALUES; public *; } # OkHttp3 -keep class okhttp3.internal.**{*;} # Retrofit -keep class retrofit2.** { *; } # RxJava RxAndroid的混淆,勿动 -keepclassmembers class rx.internal.util.unsafe.*ArrayQueue*Field* { long producerIndex; long consumerIndex; } -keepclassmembers class rx.internal.util.unsafe.BaseLinkedQueueProducerNodeRef { rx.internal.util.atomic.LinkedQueueNode producerNode; } -keepclassmembers class rx.internal.util.unsafe.BaseLinkedQueueConsumerNodeRef { rx.internal.util.atomic.LinkedQueueNode consumerNode; } # FastJson -keep class com.alibaba.fastjson.** { *; } # 权限 yanzhenjie.permission -keepclassmembers class ** { @com.yanzhenjie.permission.PermissionYes ; } -keepclassmembers class ** { @com.yanzhenjie.permission.PermissionNo ; }