How to obfuscate an Android application android混淆(Obfuscate)

原创 2010年05月25日 13:17:00


Obfuscate an Android application 这篇文章的作者介绍了如何在Android平台下混淆程序,并且给出antbuild.xml文件,经过自己的测试,发现里面少了一些target项,在Eclips会出错,后来结合zxing开源项目的build.xml文件,终于混淆成功,项目包减少了不少。








项目 –> properties –> builders –> new –> ant builder



接着Buildfile选择项目build.xml文件,Base Dir选择项目目录就行了,记得勾上你的builders







  1. <property name="proguard-home" value="D://Program Files//proguard4.2//lib//"/>  
  3.     <target name="optimize" depends="compile">  
  4.         <jar basedir="${outdir-classes}" destfile="temp.jar"/>  
  5.         <java jar="${proguard-home}/proguard.jar" fork="true" failonerror="true">  
  6.             <jvmarg value="-Dmaximum.inlined.code.length=32"/>  
  7.             <arg value="-injars temp.jar"/>  
  8.             <arg value="-outjars optimized.jar"/>  
  9.             <arg value="-libraryjars ${android-jar}"/>  
  10.             <!-- <arg value="-libraryjars ${library-jar}/some_lib_used.jar"/> -->  
  11.             <arg value="-dontpreverify"/>  
  12.             <arg value="-dontoptimize"/>  
  13.             <arg value="-dontusemixedcaseclassnames"/>  
  14.             <arg value="-repackageclasses ''"/>  
  15.             <arg value="-allowaccessmodification"/>  
  16.             <arg value="-keep public class com.iwidsets.WidsetsActivity"/>  
  17.             <!-- <arg value="-keep public class com.just2me.obfapp.receiver.*"/> -->  
  18.             <arg value="-optimizationpasses 7"/>  
  19.             <arg value="-verbose"/>  
  20.             <arg value="-dontskipnonpubliclibraryclasses"/>  
  21.             <arg value="-dontskipnonpubliclibraryclassmembers"/>  
  22.         </java>  
  23.         <delete file="temp.jar"/>  
  24.         <delete dir="${outdir-classes}"/>  
  25.         <mkdir dir="${outdir-classes}"/>  
  26.         <unzip src="optimized.jar" dest="${outdir-classes}"/>  
  27.         <delete file="optimized.jar"/>  
  28.     </target>  


注意:keep public class com.iwidsets.WidsetsActivity需改成你的主Activity


 并修改target dex


  1. <!-- Convert this project's .class files into .dex files. -->  
  2. <target name="dex" depends="compile,optimize">  
  3.     <echo>Converting compiled files and external libraries into ${out-folder}/${dex-file}...</echo>  
  4.     <apply executable="${dx}" failonerror="true" parallel="true">  
  5.         <arg value="--dex" />  
  6.         <arg value="--output=${intermediate-dex-location}" />  
  7.         <arg path="${outdir-classes-location}" />  
  8.         <fileset dir="${external-libs-folder}" includes="*.jar"/>  
  9.     </apply>  
  10. </target>  


  • 大小: 4.9 KB
  • 大小: 27.1 KB
  • 大小: 25.5 KB
  • 大小: 6.4 KB







There is no easy way to obfuscate Java classes of an Android app. This is no Eclipse plugin, nor even a working ant script.

Maybe there are working ant scripts. But for Android SDK 1.5, it seems like no one has supplied a proper one, yet. And hence, I spent half a day hacking out a script that works. There are more effort and hurdles than what are presented here.. but for a simple working script, here it is how I did it:


1 Create a Project

From the Terminal, in /android-sdk/tools/, run:

./android create project –target 2 –path /PATH/TO/ObfuscatedApp –activity MyActivity –package com.just2me.obfapp


2 Edit build.xml

Replace the build.xml with my modified build.xml, which is the most important item in this tutorial. The obfuscation work is in the optimize target as seen below.

ant build.xml

Some points to note in the build.xml ant script:

  • Edit the properties for the path to your Android SDK and Proguard
  • If you use any libraries, copy them to /lib and add -libraryjars ${library-jar}/some_lib_used.jar accordingly
  • -dontoptimize is needed for Android
  • For all classes that are declared in AndroidManifest.xml Application nodes (Activities, Receviers, etc), add an arg to tell proguard not to obfuscate. Exampe: "-keep public class com.just2me.obfapp.activity.*"


3 Run ant

The last step is to simply run the ant script!

To package a debug version that is signed with a debug key, run "ant debug-obf".

To package a release version that is unsigned, run "ant release-obf".

If all is well, then you will find the products in /bin. ObfuscatedApp-debug.apk would be the debug package that could be installed on simulator/devices.


How to obfuscate an Android application

There is no easy way to obfuscate Java classes of an Android app. This is no Eclipse plugin, nor eve...
  • zhjp4295216
  • zhjp4295216
  • 2010年09月28日 09:54
  • 618


《Obfuscate an Android application》 这篇文章的作者介绍了如何在Android平台下混淆程序,并且给出ant的build.xml文件,经过自己的测试,发现里面少了一些t...
  • zhjp4295216
  • zhjp4295216
  • 2010年09月26日 16:40
  • 468


  • bihansheng2010
  • bihansheng2010
  • 2016年05月09日 14:49
  • 2965

免费的.netFramework 混淆工具 Babel obfuscator GUI

免费的.netFramework 混淆工具 Babel obfuscator GUI The GUI tool of Babel obfuscator this tools Support Bab...
  • luozhuang
  • luozhuang
  • 2010年03月31日 14:47
  • 3056

Java 混淆器(obfuscate)

Java 混淆器就是给.class加密以防止反编译的工具 开源的  RetroGuard IBM的  JAX           ...
  • dragondwy
  • dragondwy
  • 2008年07月09日 23:25
  • 647

ant script to obfuscate android code

最近正在做CHINA区的build machine. J2ME已经开始大规模使用,公司最近要支持OPHONE手机,于是也把ANDROID支持到buildmachine里去。android有自己的ant...
  • seafit
  • seafit
  • 2010年06月11日 13:02
  • 1745

Java Obfuscator的原理

Java Obfuscator的原理就是将字节码转换为一个逻辑上的对等物,这种转换后的版本极难拆散。即使有人试图去反编译,过程将极其艰难复杂,并很难绕过转换后模糊晦涩的编码。主要的过程如下: ...
  • simayilong
  • simayilong
  • 2010年11月15日 11:48
  • 1106

Beyond SQLi: Obfuscate and Bypass

Beyond SQLi: Obfuscate and Bypass |=-------------------------------------------------------------...
  • cnbird2008
  • cnbird2008
  • 2013年08月23日 11:31
  • 1212

Obfuscate for Untiy3D 代码混淆器

圣典文章:   Obfuscate your code making code e...
  • ldghd
  • ldghd
  • 2012年12月24日 11:41
  • 1950

Obfuscate4e - Obfuscate your java code

Obfuscate4e integrates obfuscation into the Eclipse PDE build process. It enables obfuscation of you...
  • DavidHsing
  • DavidHsing
  • 2011年11月09日 09:31
  • 4330
您举报文章:How to obfuscate an Android application android混淆(Obfuscate)