After several days, I checked hundreds of websites and finally found a simple ant obfuscation compiling method. Start as follows:
1. For a common project, first add the ant compilation function to it.
Android update project -- name project_name-t 3-p D:/temp/project_name
An ant script named build. xml is automatically generated in the project root directory. The project name above is your project name.
2. added the obfuscation function
In the first step, ant can be used for compilation in the command line. In Android, the rule file under the Directory D:/android-sdk-windows/tools/ant/main_rules.xml is automatically called when the command ant debug is entered, so you don't need to write your own ant script. Since it will call the default rule file (the default file does not include the obfuscation function), we want to confuse it and simply modify it on this rule file. Add a target after the target named-dex. The Code is as follows:
<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 "> <! -- Value = "-libraryjars $ {library-jar}/some_lib_used.jar"> --> </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> </jar> </target>
Change the path involved in the above Code to the local path. <Arg value = "-ignorewarning"/> This line is added by yourself, meaning ignore warnings.
Then perform a obfuscation dependency in the target named-dex. After adding the dependency, the Code is as follows:
<Target name = "-dex" depends = "compile, optimize,-post-compile,-obfuscate" unless = "do. not. compile "> <if condition =" $ {manifest. hasCode} "> <then> <dex-helper> </then> <else> <echo> hasCode = false. skipping... </echo> </else> </if> </target>
In fact, only optimize is added, which means that this target depends on target optimize.
3. Start Compilation
It can be compiled in the command line. After compilation, the class. dex is decompiled. It can be seen that the obfuscation is successful. I don't know why the decompilation won't come back in our project, but it can ensure that obfuscation is successful. I have decompiled other examples of projects after compilation. You can see: (sorry, you cannot upload images within one week of registration)
Now add: