主要修改2个文件 default.properties 和 proguard.cfg
首先先看看原始文件的内容
default.properties
# This file is automatically generated by Android Tools.
# Do not modify this file -- YOUR CHANGES WILL BE ERASED! # # This file must be checked in Version Control Systems. # # To customize properties used by the Ant build system use, # "build.properties", and override values to adapt the script to your # project structure. # Project target. target=android-8 # Indicates whether an apk should be generated for each density. split.density=false
-optimizationpasses 5-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>;}-keepclasseswithmembernames class * { public <init>(android.content.Context, android.util.AttributeSet);}-keepclasseswithmembernames class * { public <init>(android.content.Context, android.util.AttributeSet, int);}-keepclassmembers enum * { public static **[] values(); public static ** valueOf(java.lang.String);}-keep class * implements android.os.Parcelable { public static final android.os.Parcelable$Creator *;}
如果说你项目没有引用第三方包,就只要在default.properties 加入 proguard.config=proguard.cfg
# This file is automatically generated by Android Tools.
# Do not modify this file -- YOUR CHANGES WILL BE ERASED! # # This file must be checked in Version Control Systems. # # To customize properties used by the Ant build system use, # "build.properties", and override values to adapt the script to your # project structure. # Project target. target=android-8proguard.config=proguard.cfg # Indicates whether an apk should be generated for each density. split.density=false如果有第三方包,则需要修改 proguard.cfg 忽略第三方包的混淆
-optimizationpasses 5
-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>; } -keepclasseswithmembernames class * { public <init>(android.content.Context, android.util.AttributeSet); } -keepclasseswithmembernames class * { public <init>(android.content.Context, android.util.AttributeSet, int); } -keepclassmembers enum * { public static **[] values(); public static ** valueOf(java.lang.String); } -keep class * implements android.os.Parcelable { public static final android.os.Parcelable$Creator *; }-ignorewarnings-libraryjars lib/GuoTengTermb.jar-libraryjars lib/ksoap2-android-assembly-2.4-jar-with-dependencies.jar-libraryjars lib/httpmime-4.1.3.jar-libraryjars lib/idreadsdk.jar-libraryjars libs/MapApi.jar -dontskipnonpubliclibraryclassmembers -dontskipnonpubliclibraryclasses-keep class org.kobjects.**{*;}-keep class guoTeng.IC2ReadCard.**{*;}-keep class com.fri.idcread.**{*;}-keep class org.apache.http.entity.**{*;}-keep class com.amap.mapapi.**{*;}-keep class com.autonavi.aps.api.**{*;}-keep class com.mapabc.minimap.map.vmap.**{*;} -keepclassmembers class * extends android.app.Activity { public void *(android.view.View); } -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(); } -------------------------------------------------------------这样导包apk时,就是代码混淆的的apk了