http://www.myexception.cn/android/1477945.html
由于各种反编译工具的泛滥,作为Android程序员在2.3版本以前只能通过手动添加proguard来实现代码混淆

proguard这个工具是一个java代码混淆的工具

在2.3版本的sdk中我们可以看到在android-sdk-windows/tools/下面多了一个proguard文件夹
google已经把proguard技术放在了androidsdk里面 可以通过正常的编译方式也能实现代码混淆了
代码混淆proguard技术引见及使用步骤ZZ" title="Android代码混淆proguard技术引见及使用步骤ZZ" style="margin:0px; padding:0px; max-width:579px; height:auto; font-family:Tahoma; line-height:24px" width="1" height="1">
可以看见新建一个工程里面有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-9

我们可以看到proguard.cfg已经帮我们写好了优化代码脚本
-optimizationpasses 5-dontusemixedcaseclassnam<wbr>es-dontskipnonpubliclibrary<wbr>classes-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 com.android.vending.licensing.ILicensingService-keepclasseswithmembernam<wbr>es class * {    native ;}-keepclasseswithmembernam<wbr>es class * {    public (android.content.Context, android.util.AttributeSet);}-keepclasseswithmembernam<wbr>es class * {    public (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 *;}</wbr></wbr></wbr></wbr></wbr>

从脚本中可以看到,混淆中保留了继承自Activity、Service、Application、BroadcastReceiver、ContentProvider等基本组件以及com.android.vending.licensing.ILicensingService

并保留了所有的Native变量名及类名,所有类中部分以设定了固定参数格式的构造函数,枚举等等。(详细信息请参考/examples中的例子及注释。)

接下来按照google帮助文档里说的
引用 To enable ProGuard so that it runs as part of an Ant or Eclipsebuild, set the proguard.config property in the /default.propertiesfile. The path can be an absolute path or a path relative to theproject's root.
所以我们修改default.propertiesfile
加上一句
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-9  proguard.config=proguard.cfg

然后正常的编译签名即可

然后用AndroidTools生成一个发布的apk即可
代码混淆proguard技术引见及使用步骤ZZ" title="Android代码混淆proguard技术引见及使用步骤ZZ" style="margin:0px; padding:0px; max-width:579px; height:auto; font-family:Tahoma; line-height:24px" width="1" height="1">
然后用反编译工具查看dex文件
最后导出反编译之后的混淆代码如下图
代码混淆proguard技术引见及使用步骤ZZ" title="Android代码混淆proguard技术引见及使用步骤ZZ" style="margin:0px; padding:0px; max-width:579px; height:auto; font-family:Tahoma; line-height:24px" width="1" height="1">
是不是很轻松加愉快!希望各位程序员都能保护好自己的Android代码!

更多相关文章

  1. 一段漂亮的Fragment hide,show相关的代码
  2. android 周报 - 2019/10/6-Issue #382
  3. Android Studio 快捷键
  4. 【Android】说做就做:偶的头像华丽的漂浮在map上。。。
  5. Android中如何获取系统中所有的应用程序
  6. Pool, SimplePool与SynchronizedPool
  7. Android(安卓)之AES加密,解密与后台进行数据交互
  8. Android(安卓)ListView setOnItemClickListener/setOnItemSelect
  9. Android(安卓)Studio 2.0代码热更新

随机推荐

  1. 【魔幻塔防】128关配置文件
  2. android自带图标
  3. 【魔幻塔防】80关配置文件
  4. android widget
  5. android 设置EditText只能输入数字
  6. Android四大组件的工作过程
  7. Android ListView 的简单用法
  8. Android Development
  9. 完美解决listView滚动条隐藏的问题!
  10. 拥抱 Android Studio 之一:从 ADT 到 Andr