Use IntelliJ IDEA to configure Allatori for code obfuscation when developing Android applications, intellijallatori
IntelliJ IDEA provides very powerful Android development support. Even Android Studio officially recommended by Google is actually a dedicated Android development version of IntelliJ IDEA. Because the Android program uses the APK file Encapsulation Format when it is released, it is still a virtual machine bytecode and can be decompiled using tools such as dex2jar and jd, therefore, prior to product release, we must use bytecode obfuscation to maximize protection of software intellectual property rights. The obfuscation effects of ProGuard obfuscators officially recommended by Google are not satisfactory. Therefore, various professional obfuscators have emerged, and Allatori is the best. Allatori is a commercial obfuscator software with a very high obfuscation intensity. However, its latest official website provides an integration method with Android Studio, which uses the gradle build tool configuration mode, the test fails. Allatori's own document describes how to work with the Ant build tool. Therefore, we still need to consider implementing the automatic cooperation between Allatori and Android development in IntelliJ IDEA.
First, create a subdirectory named allatori in the hard drive directory of the IDEA Android Module, and copy all the jar files of Allatori to this subdirectory. Then create two XML files in the directory where the IDEA Android Module is located, one is Allatori's own obfuscation configuration file named config-allatori.xml; the other is the configuration file for Ant build, named build-allatori.xml. First look at the content of the config-allatori.xml file, basically can be used as a template:
1 <?xml version="1.0" encoding="UTF-8"?> 2 <config> 3 <jars> 4 <dir in="${out.classes.absolute.dir}" out="${out.classes.absolute.dir}-obfuscated"/> 5 </jars> 6 7 <classpath> 8 <jar name="libs/netty/netty-all-4.0.19.Final.jar"/> 9 </classpath>10 11 <keep-names>12 <class template="public class * instanceof android.app.Activity">13 <method template="public void *(android.view.View)"/>14 </class>15 <class template="public class * instanceof android.app.Application"/>16 <class template="public class * instanceof android.app.Service"/>17 <class template="public class * instanceof android.view.View">18 <method template="public void set*(**)"/>19 </class>20 <class template="public class * instanceof android.content.BroadcastReceiver"/>21 <class template="public class * instanceof android.content.ContentProvider"/>22 <class template="public class * instanceof android.app.backup.BackupAgentHelper"/>23 <class template="public class * instanceof android.preference.Preference"/>24 <class template="public class com.android.vending.licensing.ILicensingService"/>25 <class template="public class com.google.android.vending.licensing.ILicensingService"/>26 <class template="class * implements android.os.Parcelable">27 <field template="public static final android.os.Parcelable$Creator *"/>28 </class>29 30 <class template="class io.netty.*">31 <field access="private+"/>32 <method template="private+ *(**)"/>33 </class>34 </keep-names>35 36 <property name="log-file" value="log.xml"/>37 </config>
Pay attention to row 4th, $ {out. classes. absolute. dir} and $ {out. classes. absolute. dir}-obfuscated are custom variables in the build-allatori.xml, used to indicate IDEA compiled Android Module source code generated java class file (bytecode) directory and the directory where the class files are obfuscated and saved. Lines 7th to 9 indicate the class path of the third-party library referenced in the Android Module. If there are multiple third-party library jar files, the corresponding multi-row class path description is required. Lines 30th to 33 indicate that the classes in the third-party library should not be obfuscated. You can specify the package name prefix and wildcard characters. If there are multiple third-party class libraries, there must be multiple such declarations.
Next let's take a look at the content of the build-allatori.xml file, you can also be used as a template:
1 <? Xml version = "1.0" encoding = "UTF-8"?> 2 <project name = "your module name-allatori" default = "your module name-obfuscated"> 3 4 <property name = "out. classes. absolute. dir "value ="/your project absolute path/out/production/your module name "/> 5 <property name =" out. jar. absolute. dir "value ="/your project absolute path/out/artifacts/your module name "/> 6 7 <target name =" your module name-obfuscated "> 8 <taskdef name = "allatori" classname = "com. allatori. ant. obfuscatorTask "classpath =" allatori/allatori. jar "/> 9 <allatori config =" config-allatori.xml "/> 10 <delete dir =" $ {out. classes. absolute. dir} "/> 11 <move todir =" $ {out. classes. absolute. dir} "> 12 <fileset dir =" $ {out. classes. absolute. dir}-obfuscated "/> 13 </move> 14 </target> 15 16 <target name =" your module name-clean "> 17 <delete dir =" $ {out. classes. absolute. dir} "/> 18 <delete dir =" $ {out. jar. absolute. dir} "/> 19 <delete dir =" $ {out. classes. absolute. dir}-obfuscated "/> 20 </target> 21 </project>
You need to replace all the words "your module name" in the build-allatori.xml with the actual name of your Android Module, change the words "your project absolute path" to the absolute path of your project. The following adds the build-allatori.xml to the Ant Build of IDEA, as shown in:
Click the Ant Build button in the upper-right corner of IDEA, click the "+" button in the pop-up Dock window, and select the build-allatori.xml file to add it to the Ant Build system of IDEA.
Then, in the IDEA Project Stucture configuration, create the Artifacts of the Android Module. In the specific attribute configuration of its Artifacts, you need to specify its Pre-processing to use the target defined in the build-allatori.xml named "your module name-obfuscated", as shown in:
Note that in the red area, check the Run Ant target and click "... "button, the selection window appears, you need to select the target defined in the build-allatori.xml named" your module name-obfuscated.
Then, click "Build"> "Build Artifacts..." in the IDEA menu... "menu item and select the" Build "command to compile and Build the Android APK. Then remember to execute the Build Artifacts Build again (never Rebuild !) Command to achieve obfuscation and re-build the APK. That is, the Build command of Artifacts is used to Build the APK by compiling obfuscation. The principle is that during the first Build, after compiling and generating class files, Allatori is automatically called to confuse class files, however, the first Build to generate an APK is still based on unobfuscated class files. Therefore, in the second Build, because the compiled and obfuscated class file already exists and does not need to be re-compiled, IDEA will directly use the obfuscated class file to Build the APK, so as to achieve the goal of building an APK by obfuscation.
Also note that if you need to clear the class files and APK generated by the Android Module, You can execute the "your module name-clean" target defined in the build-allatori.xml through the Ant Build of IDEA, the generated class file directory and APK directory can be completely cleared.