Android的混淆主要分如下几个步骤:
一. 打开project.properties文件的如下代码(在比较新的版本中适用,低版本需要另外方式)
# To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home): proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt//主要是放开这句话 #Project target. target=android-19
主要是分为三类
1.系统的一些方法等
2.是引入的三方jar包
3.是引入的依赖库
下面直接上我项目的代码
//这部分是一个常规的设置
-optimizationpasses 7 -dontusemixedcaseclassnames -dontskipnonpubliclibraryclasses -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 <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); } -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 enum * { public static **[] values(); public static ** valueOf(java.lang.String); } -keep class * implements android.os.Parcelable { public static final android.os.Parcelable$Creator *; } -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 *Annotation* -keepattributes Exceptions,InnerClasses,Signature -keepattributes SourceFile,LineNumberTable //这是不混淆我自己项目中的包下的所有文件 -keep class com.stateunion.goldencloud.Entity** {*;} //指定类不进行混淆(包括里面的方法等) #-keepclasseswithmembers class MyBean { # <fields>; # <methods>; #} //v4包和他的子类的设置,继承自fragment的类 -keep class **.R$* { *; } -libraryjars libs/android-support-v4.jar -dontwarn android.support.v4.** -keep class android.support.v4.** { *; } -keep interface android.support.v4.** { *; } -keep public class * extends android.support.v4.** -keep public class * extends android.app.Fragment //这部分为三方依赖的库的声明 -libraryjars ..\\xutillibrary -dontwarn com.lidroid.xutils.** -keep class com.lidroid.xutils.** {*;} -libraryjars ../SystemBarTint-master -dontwarn com.readystatesoftware.systembartint.** -keep class com.readystatesoftware.systembartint.**{*;} -libraryjars ../android-support-v7-appcompat -dontwarn com.android-support-v7-appcompat.** -keep class com.android-support-v7-appcompat.**{*;} //这是libs下的jar包声明 -libraryjars libs/fastjson-1.1.40.jar -dontwarn com.alibaba.fastjson.** -keep class com.alibaba.fastjson.**{*;} -libraryjars libs/gson-2.2.4.jar -dontwarn com.google.gson.** -keep class com.google.gson.**{*;}
目前也有三方加密的方式,通过应用加壳的方式进行加密,有兴趣的同学可以去网上看看 例如爱加密等。
下面是我反编译后的结果图
1. 这是没有混淆的xutils
2.这是保留后的实体类
3.这是混淆后的文件