Android用Proguard混淆代码

在Android4.0之前的版本建的工程中有一个proguard.cfg文件,混淆时直接将混淆代码加进去,然后在project.properties这个文件底下加入proguard.config=proguard.cfg这句话就可以了;

在4.0版本建的工程中发现proguard.cfg没了,多了proguard-project.txt这个文件。反正我没管,直接将 proguard.cfg这个文件拷过去用了,没发现什么问题,下面是混淆时proguard.cfg中的代码:

-optimizationpasses 5
-dontusemixedcaseclassnames
-dontskipnonpubliclibraryclasses
-dontpreverify
-verbose
-optimizations !code/simplification/arithmetic,!field/*,!class/merging/*
-keepattributes *Annotation*
-keepattributes JavascriptInterface


-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);
}


-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关键字修饰的一些都是不需要混淆处理的
-libraryjars   libs/android-support-v4.jar
-libraryjars   libs/commons-io-1.3.2.jar
-libraryjars   libs/library.jar
-libraryjars   libs/pushservice-2.4.0.jar
-libraryjars   libs/nineoldandroids-2.4.0.jar




## commons-io-1.3.2.jar
-keep public class org.apache.commons.** {*;} 


## support-v4
-dontwarn android.support.v4.**    
-keep class android.support.v4.** { *; }  
-keep interface android.support.v4.app.** { *; }  
-keep public class * extends android.support.v4.**  
-keep public class * extends android.app.Fragment


## annotations.jar
-keep public class android.annotation {*;}


## pushservice-2.4.0.jar
-keep public class android.content.pm {*;}
-keep public class android.baidu.** {*;} 


## nineoldandroids-2.4.0.jar
-keep public class com.nineoldandroids.** {*;}


## library.jar
-keep public class com.nostra13.universalimageloader.** {*;} 


## kxml2-min-2.3.0.jar
-keep public class org.** {*;}



最后别忘了将proguard.config=proguard.cfg这句话加入到project.properties这个文件下面

你可能感兴趣的:(ProGuard,android混淆)