Created
October 15, 2017 17:01
-
-
Save ownwell/6c8d31e2823a25d6bce4a352027ab2e4 to your computer and use it in GitHub Desktop.
混淆规则
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 | |
# We want to keep methods in Activity that could be used in the XML attribute onClick | |
# 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 | |
# We want to keep methods in Activity that could be used in the XML attribute onClick | |
# 代码混淆压缩比,在0和7之间,默认为5,一般不需要改 | |
-optimizationpasses 5 | |
# 混淆时不使用大小写混合,混淆后的类名为小写 | |
-dontusemixedcaseclassnames | |
# 指定不去忽略非公共的库的类 | |
-dontskipnonpubliclibraryclasses | |
# 指定不去忽略非公共的库的类的成员 | |
-dontskipnonpubliclibraryclassmembers | |
# verbose log相关 | |
# 包含有类名->混淆后类名的映射关系 | |
# 然后使用printmapping指定映射文件的名称 | |
-verbose | |
-printmapping proguardMapping.txt | |
# 指定混淆时采用的算法,后面的参数是一个过滤器 | |
# 这个过滤器是谷歌推荐的算法,一般不改变 | |
-optimizations !code/simplification/arithmetic,!field/*,!class/merging/* | |
# 保护代码中的Annotation不被混淆,这在JSON实体映射时非常重要,比如fastJson | |
-keepattributes *Annotation* | |
# 避免混淆泛型,这在JSON实体映射时非常重要,比如fastJson | |
-keepattributes Signature | |
# 抛出异常时保留代码行号,在异常分析中可以方便定位 | |
-keepattributes SourceFile,LineNumberTable | |
### ---- android开发必要混淆文件 | |
# 保留所有的本地native方法不被混淆 | |
-keepclasseswithmembernames class * { | |
native <methods>; | |
} | |
# 保留了继承自Activity、Application这些类的子类 | |
# 因为这些子类,都有可能被外部调用 | |
# 比如说,第一行就保证了所有Activity的子类不要被混淆 | |
-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.app.backup.BackupAgentHelper | |
-keep public class * extends android.preference.Preference | |
-keep public class * extends android.view.View | |
-keep public class com.android.vending.licensing.ILicensingService | |
# 如果有引用android-support-v4.jar包,可以添加下面这行 | |
-keep public class com.xxxx.app.ui.fragment.** {*;} | |
# 保留在Activity中的方法参数是view的方法, | |
# 从而我们在layout里面编写onClick就不会被影响 | |
-keepclassmembers class * extends android.app.Activity { | |
public void *(android.view.View); | |
} | |
# 枚举类不能被混淆 | |
-keepclassmembers enum * { | |
public static **[] values(); | |
public static ** valueOf(java.lang.String); | |
} | |
# 保留自定义控件(继承自View)不被混淆 | |
-keep public class * extends android.view.View { | |
*** get*(); | |
void set*(***); | |
public <init>(android.content.Context); | |
public <init>(android.content.Context, android.util.AttributeSet); | |
public <init>(android.content.Context, android.util.AttributeSet, int); | |
} | |
# 保留Parcelable序列化的类不被混淆 | |
-keep class * implements android.os.Parcelable { | |
public static final android.os.Parcelable$Creator *; | |
} | |
# 保留Serializable序列化的类不被混淆 | |
-keepclassmembers class * implements java.io.Serializable { | |
static final long serialVersionUID; | |
private static final java.io.ObjectStreamField[] serialPersistentFields; | |
private void writeObject(java.io.ObjectOutputStream); | |
private void readObject(java.io.ObjectInputStream); | |
java.lang.Object writeReplace(); | |
java.lang.Object readResolve(); | |
} | |
# 对于R(资源)下的所有类及其方法,都不能被混淆 | |
-keep class **.R$* { | |
*; | |
} | |
# 自定义的 | |
-keepclassmembers class * extends android.webkit.WebViewClient { | |
public void *(android.webkit.WebView, java.lang.String, android.graphics.Bitmap); | |
public boolean *(android.webkit.WebView, java.lang.String); | |
} | |
-keepclassmembers class me.cyning.proguard.WebViewActivity$JSInterfacel { | |
<methods>; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment