The author of the article "obfuscate an Android Application" describes how to confuse programs on the Android platform and give ant build. XML file. After testing, we found that some target items were missing, and errors occurred in ipvs. Later, we combined the zxing open-source project build. the XML file is finally obfuscated successfully, and the project package is reduced a lot.
Here are some important notes that do not provide source code.
1. Create the build. xml file
Create a file named build. XML in the project directory.
2. Create an ant package
Project-> properties-> builders-> New-> ant Builder
Next, select the Project Build. xml file for buildfile, and select the project directory for base dir. Remember to check your builders.
3. Modify the build. xml file
The zxing file does not include the confusion package option, so you have to make some modifications, as shown in the following example:
XML Code
- <Property name = "proguard-home" value = "D: // program files // proguard4.2 // lib //"/>
- <Target name = "optimize" depends = "compile">
- <Jar basedir = "$ {outdir-classes}" destfile = "Temp. Jar"/>
- <Java jar = "$ {proguard-home}/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}"/>
- <! -- <Arg 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 com. iwidsets. widsetsactivity"/>
- <! -- <Arg value = "-keep public class com. just2me. obfapp. Er er. *"/> -->
- <Arg value = "-optimizationpasses 7"/>
- <Arg value = "-verbose"/>
- <Arg value = "-dontskipnonpubliclibraryclasses"/>
- <Arg value = "-dontskipnonpubliclibraryclassmembers"/>
- </Java>
- <Delete file = "Temp. Jar"/>
- <Delete dir = "$ {outdir-classes}"/>
- <Mkdir dir = "$ {outdir-classes}"/>
- <Unzip src = "optimized. Jar" DEST = "$ {outdir-classes}"/>
- <Delete file = "optimized. Jar"/>
- </Target>
Note: change keep public class com. iwidsets. widsetsactivity to your main activity.
And modify target Dex.
XML Code
- <! -- Convert this project's. class files into. Dex files. -->
- <Target name = "Dex" depends = "compile, optimize">
- <Echo> converting compiled files and external libraries into $ {out-Folder}/$ {Dex-file}... </echo>
- <Apply executable = "$ {DX}" failonerror = "true" parallel = "true">
- <Arg value = "-- Dex"/>
- <Arg value = "-- output =$ {Intermediate-Dex-location}"/>
- <Arg Path = "$ {outdir-classes-location}"/>
- <Fileset dir = "$ {external-libs-Folder}" includes = "*. Jar"/>
- </Apply>
- </Target>