1. For a common project, first add the ant build function to it.
The code is as follows |
Copy Code |
Android Update Project--name project_name-t 3-p d:/temp/project_name |
An ant script named Build.xml is automatically generated at the project root. The project_name above is the name of your project.
2. Add Obfuscation function
In the first step, you can already compile with ant on the command line. Because this is true of Android, the rules file in the D:/android-sdk-windows/tools/ant/main_rules.xml directory is automatically invoked when you enter command ant debug, so you don't have to write your own ant script. Now that it calls the default rule file (the default file does not add obfuscation), then we want to confuse it and modify it directly on the rule file. After target named-dex, add a target with the following code:
code is as follows |
copy code |
1 <target name= "optimize" depends= "compile" > <jar basedir= "${out.classes.absolute.dir}" Destfile= "Temp.jar" > <java jar= "D:/android-sdk-windows/tools/proguard/lib/proguard.jar" Fork= "true" failonerror= "true" ><jvmarg value= "-dmaximum.inlined.code.length=32" > <arg value= "-injars temp.jar" ><arg value= "-outjars optimized.jar" ><arg value = "-libraryjars ' ${android.jar} '" ><!--value= "-libraryjars ${library-jar}/some_lib_used.jar" >-->< Arg value= "-dontpreverify" ><arg value= "-dontoptimize" ><arg value= "-dontusemixedcaseclassnames" > <arg value= "-repackageclasses" ><arg value= "-allowaccessmodification" > <arg value= "-keep public class * extends Android.app.Activity" > <arg value= "-keep public class * extends Android.app.Service" > <arg value= "-keep public class * extends Android.content.BroadcastReceiver "> <arg value="- Keep public class * extends Android.content.ContentProvider "> <arg value= "-keep public class * extends Android.view.View" > <arg value= "-optimizationpasses 1" > <arg value= "-verbose" ><arg value= "-dontskipnonpubliclibraryclasses" ><arg value= "-dontskipnonpubliclibraryclassmembers" ><arg value= "-ignorewarning" > </arg></arg></arg></arg></ arg></arg></arg></arg></arg></arg></arg></arg></arg></ arg></arg></!--></arg></arg></arg></jvmarg></java> <delete file= "Temp. Jar "> <delete dir=" ${out.classes.absolute.dir} "> <mkdir dir=" ${ Out.classes.absolute.dir} "> <unzip src=" Optimized.jar "mce_src=" Optimized.jar "dest=" ${ Out.classes.absolute.dir} "> <delete file=" Optimized.jar "></delete></unzip ></mkdir></delete></delete></jar></target> |
Modify the path where the above code involves the path and change the cost. <arg value= "-ignorewarning"/> This line was added by itself, meaning to ignore the warning.
Then a confusing dependency is made in target named-dex, and the following code is added:
The code is as follows |
Copy Code |
1 <target Name= "-dex" depends= "compile, optimize,-post-compile,-obfuscate" unless= "Do.not.compile" > <if condition= "${manifest.hascode}" > <then> <dex-helper> </ dex-helper></then> <else> <echo>hascode = False. skipping...</echo> </else> </if></target> |
Actually, it's just optimize, meaning this target relies on target optimize.
3. Start compiling
Can be compiled on the command line, compiled to Class.dex, can be seen to confuse success. Do not know why in our project decompile does not come back, but can ensure that confusion is successful. I have taken other examples of projects compiled after the decompile, you can look at the following figure: (sorry, registration within a week can not upload pictures)