Ant Build

DexGuard can be integrated in the Ant build process of the Android SDK Tools (revision 21.0.0 or higher).

Setting up the Ant build

You can enable DexGuard in the Android Ant build as follows:
  1. Copy the two configuration files from DexGuard's ant directory to the main directory of your Android project:
    dexguard-project.txt
    custom_rules.xml
    
  2. Specify the main DexGuard directory on your system in the configuration file local.properties in your Android project. For instance:
    dexguard.dir=/usr/local/DexGuard5.0
    
The standard Ant build process will now automatically use DexGuard's Ant task for your Android project. You'll see this in the build process: the lines with [dexguard] in the console replace all lines with [proguard], [dex], [dx], [apkbuilder], [signjar], and [zip-align].

DexGuard is most commonly applied to final application projects. This is the easiest and most effective approach, since it processes the combined code in a single step.

DexGuard can also be applied to library projects, if the library jar is the final product. You should then take some care with class encryption, as discussed for the class encryption option. Furthermore, tamper detection is only supported if the final application is also built and packaged using DexGuard.

You can find examples of working projects in the directory samples.

Building

The procedure for building Android applications and libraries remains the same. You can invoke ant with the usual targets, such as debug and release. For instance, to build the release version of your application and install it on a connected device:
ant release install
Debug builds use debug settings, without optimization or obfuscation. Release builds use release settings, with full optimization and obfuscation. Applications can optionally be signed. The entries in application archives are always zip-aligned for efficiency.

The Ant build picks up custom configurations from the following optional files in your Android project:

dexguard-project.txt         (for all targets)
dexguard-project-debug.txt   (for target 'debug')
dexguard-project-release.txt (for target 'release')
proguard-project.txt         (for backward compatibility with ProGuard)
The default version of the first file contains a number of settings that can be enabled to perform string encryption, class encryption, and to hide access to sensitive APIs.

Further tips

As before, you can specify some useful properties in the Ant configuration file local.properties:

Reverting to the traditional Ant build

You can go back to the basic Ant build of the Android SDK by removing or renaming the custom rules file custom_rules.xml in the main directory of your Android project.
Copyright © 2002-2014 Saikoa BVBA.