Intellij idea 和android studio 代码给混淆

Intellij idea 和android studio 代码给混淆

一、指令说明
-optimizationpasses 5 # 指定代码的压缩级别
-dontusemixedcaseclassnames # 是否使用大小写混合
-dontpreverify # 混淆时是否做预校验
-verbose # 混淆时是否记录日志 -optimizations !code/simplification/arithmetic,!field/*,!class/merging/* # 混淆时所采用的算法 -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 com.android.vending.licensing.ILicensingService # 保持哪些类不被混淆 -keepclasseswithmembernames class * { # 保持 native 方法不被混淆
native <methods>;
}
-keepclasseswithmembers class * { # 保持自定义控件类不被混淆
public <init>(android.content.Context, android.util.AttributeSet);
}
-keepclasseswithmembers class * {# 保持自定义控件类不被混淆
public <init>(android.content.Context, android.util.AttributeSet, int);
}
-keepclassmembers class * extends android.app.Activity { # 保持自定义控件类不被混淆
public void *(android.view.View);
}
-keepclassmembers enum * { # 保持枚举 enum 类不被混淆
public static **[] values();
public static ** valueOf(java.lang.String);
}
-keep class * implements android.os.Parcelable { # 保持 Parcelable 不被混淆
public static final android.os.Parcelable$Creator *;
}

二、混淆实例

1、在proguard-project.txt里面配置混淆后;

2、在project.properties中添加proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt

3.混淆实例参考

-optimizationpasses 5
-dontusemixedcaseclassnames
-dontskipnonpubliclibraryclasses
-dontskipnonpubliclibraryclassmembers
-dontpreverify
-ignorewarnings
-verbose
-optimizations !code/simplification/arithmetic,!field/*,!class/merging/* -dontwarn android.support.**
-dontwarn com.handmark.**
-dontwarn android.webkit.WebView -keepclassmembers class youmengyou.bean.** {
public <fields>;
private <fields>;
public <init>();
public <init>(org.json.JSONObject);
*;
} #保持 native 方法不被混淆
-keepclasseswithmembernames class * {
native <methods>;
} #保持自定义控件类不被混淆
-keepclasseswithmembers class * {
public <init>(android.content.Context, android.util.AttributeSet);
} #保持自定义控件类不被混淆
-keepclasseswithmembers class * {
public <init>(android.content.Context, android.util.AttributeSet, int);
} #保持自定义控件类不被混淆
-keepclassmembers class * extends android.app.Activity {
public void *(android.view.View);
} #保持枚举类不被混淆
-keepclassmembers enum * {
public static **[] values();
public static ** valueOf(java.lang.String);
} -keep class * implements android.os.Parcelable {
public static final android.os.Parcelable$Creator *;
}
-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*(...);
}
-keepclassmembers class **.R$* {
public static <fields>;
public static final int *;
}
-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 void writeObject(java.io.ObjectOutputStream);
private void readObject(java.io.ObjectInputStream);
java.lang.Object writeReplace();
java.lang.Object readResolve();
}
-keepattributes Exceptions,InnerClasses,Signature
-keepattributes *Annotation*
-keepattributes SourceFile,LineNumberTable -keep public class * extends android.app.Activity
-keep public class * extends android.app.Application
-keep public class * extends android.app.IntentService
-keep public class * extends android.app.Service
-keep public class * extends android.app.backup.BackupAgentHelper
-keep public class * extends android.content.BroadcastReceiver
-keep public class * extends android.content.ContentProvider
-keep public class * extends android.preference.Preference
-keep public class com.android.vending.licensing.ILicensingService
-keep public class * extends android.widget.LinearLayout
-keep public class * extends android.widget.FrameLayout
-keep public class * extends android.widget.CheckBox
-keep class android.** { *; }
-keep public class javax.**
-keep class org.** { *; }
-keep class android.support.v4.** {*;}
-keep class android.support.v4.app.** { *; }
-keep class android.support.v4.view.** { *; }
-keep public class * extends android.support.v4.**
-keep public class android.webkit.** #加解密
#-keep public class com.jfw.utils.ThreeDES -keep interface android.support.v4.app.** { *; }
#下拉刷新
-keep class com.handmark.** { *; }

三、最后一步,打包、签名

以前总以为Intellij idea 和android studio 在proguard-project.txt里面设置以后,在编译的时候就直接把代码给混淆了,后面自己反编译才发现,什么都混淆,原来还有个操作没做,需要在Generate Signed APK (签名)的时候勾选上Run ProGuard 才行。

Intellij idea 和android studio 代码给混淆

Intellij idea 和android studio 代码给混淆

Intellij idea 和android studio 代码给混淆

Intellij idea 和android studio 代码给混淆

上一篇:oracle11gR2在rhel-6.5的开机启动脚本


下一篇:《oracle数据库递归查询以及给结果赋初值》