工具:ADT
这里我们使用android自带的proguard混淆
新建项目会有proguard-project.txt project.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 edit
# "ant.properties", and override values to adapt the script to your
# project structure.
#
# 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
这里最后一行默认是注释的,这里我们打开注释,使用proguard.config生效
#如果混淆后找不到某个jar包中类引用,可添加这行试试
-libraryjars libs/jpush-android-2.1.7.jar
-optimizationpasses 5
-dontusemixedcaseclassnames
-dontskipnonpubliclibraryclasses
-dontpreverify
#如果项目中有用到gson,那么加上这两行
-dontobfuscate
-dontoptimize
-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
-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 class com.tencent.mm.sdk.** {
*;
}
-keep class cn.sharesdk.**{
*;
}
-keep class com.mob.**{
*;
}
-keep class com.umeng.**{
*;
}
-dontoptimize
-dontpreverify
#下面是jpush相关配置,官网有
#忽略jpush混淆时报错信息
-dontwarn cn.jpush.**
-keep class cn.jpush.** { *; }
#==================gson==========================
-dontwarn com.google.**
-keep class com.google.gson.** {*;}
#==================protobuf======================
-dontwarn com.google.**
-keep class com.google.protobuf.** {*;}
这个自己看一篇就懂了,然后根据自己项目的需求自己配置
这样就可以进行代码混淆了,但是只有通过导入包才起作用,run as 或者 debug as是不会混淆的
一般的,我们会用到多渠道打包,那如果导出未签名包进行多渠道打包操作呢
右键点击你的项目->android tools->export unsigned application pakeage->导出未签名包然后进行多渠道打包即可
这个包是不能直接运行的,eclipse也会直接提示说要进行签名后才能用,这种方式打包中可能会报一个android link错误,这样解决 windows->perfercens->android->Lint Error Checking->去掉第二个(run full error check…)选项目 就OK了