Maven Plugin

DexGuard is integrated in Maven with the DexGuard Maven plugin, which is an extension of the Android Maven plugin (version 3.9.0-rc.3, for Maven version 3.1.1).

Installation

You first need to install the DexGuard Maven plugin in your local Maven repository. Assuming Maven is already in your path, you can execute the Linux script
bin/install_maven_plugin.sh
or the Windows script
bin/install_maven_plugin.bat
They invoke Maven with the proper settings to copy DexGuard to your local repository cache.

Activation

Once the plugin has been installed, you can start using it in your project. You only need to specify it in the pom.xml file of your project, typically replacing the Android Maven plugin:
<project>
    ...
    <build>
        ...
        <pluginmanagement>
            <plugins>
                <plugin>
                    <groupId>com.saikoa.dexguard.maven</groupId>
                    <artifactId>dexguard-maven-plugin</artifactId>
                    <version>5.4.00</version>
                    <extensions>true</extensions>
                </plugin>
            </plugins>
        </pluginmanagement>
        ...
    </build>
</project>

You can find a small working project in the directory samples/Maven.

Lifecycle Phases

The DexGuard plugin preserves the apk lifecycle phases of the original Android plugin. It aliases the original goals from the "android:" namespace in the "dexguard:" namespace (which is short for "com.saikoa.dexguard.maven:dexguard-maven-plugin:").

The only different goal is dexguard:apk, because it runs DexGuard, which optimizes, obfuscates, converts, signs, and zipaligns the code.

The goals android:proguard, android:dex, and android:zipalign are no longer necessary, so they don't have aliases.

Phase Plugin: goal
generate-sources dexguard: generate-sources
process-resources resources: resources
compile compiler: compile
process-test-resources resources: testResources
test-compile compiler: testCompile
prepare-package dexguard: emma
package dexguard: apk
install install: install
pre-integration-test dexguard: internal-pre-integration-test
integration-test dexguard: internal-integration-test
deploy deploy: deploy

Building

The procedure for building Android applications remains the same. You can invoke mvn with the usual targets, such as clean and package. For instance, to build the debug version of your application:
mvn clean package

The plugin creates debug builds by default. You can create release builds by adding -Dandroid.release=true on the command line or <release>true</release> in the pom.xml file of your project:

mvn -Dandroid.release=true clean package

Debug builds use debug settings, without optimization or obfuscation. Release builds use release settings, with full optimization and obfuscation. The entries in application archives are always zip-aligned for efficiency.

The DexGuard plugin can conveniently sign your applications in one go. You can specify signing parameters on the command line and in the container <sign>...</sign> in the pom.xml file of your project. For instance:

mvn -Dandroid.sign.storepass=android -Dandroid.sign.keypass=android clean package

You can then deploy the application to a connected device with the deploy or redeploy goals:

mvn dexguard:deploy

You can get help on the plugin with the help goal:

mvn dexguard:help

Plugin Parameters

The DexGuard plugin accepts parameters in its <configuration> element in the pom.xml of your project:

<project>
    ...
    <build>
        ...
        <plugins>
            <plugin>
                <groupId>com.saikoa.dexguard.maven</groupId>
                <artifactId>dexguard-maven-plugin</artifactId>
                <configuration>
                    ...    <!-- parameters go here. -->
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

Note that this configuration is not nested in the <pluginmanagement> element that was used earlier for activating the plugin.

Since the goals are the same as for the Android plugin, the parameters are the same too. Some parameters no longer have a meaning and are ignored.

Plugin Parameters for dexguard:apk

The dexguard:apk goal supports the same parameters as the android:apk goal, plus a few parameters from the android:dex goal and the android:proguard goal, for backward compatibility.

<aaptExtraArgs>string[]</aaptExtraArgs> (-Dandroid.aaptExtraArgs=string[])
Extra arguments to be passed to the aapt tool when collecting resources and assets.
<androidManifestFile>file</androidManifestFile> (default = ${project.basedir}/AndroidManifest.xml)
The AndroidManifest.xml file.
<apk>apk_configuration</apk>
Containing element for the following apk parameters.
<debug>boolean</debug> (-Dandroid.apk.debug=boolean) (default = false)
Specifies whether the apk is intended for debugging, in which case the gdbserver executable is added.
<nativeToolchain>string</nativeToolchain> (-Dandroid.nativeToolchain=string) (default = arm-linux-androideabi-4.4.3)
The name of the native toolchain, which determines the gdbserver executable to be added to a debugging apk.
<metaIncludes>string[]</metaIncludes> (-Dandroid.apk.metaIncludes=string[])
Names of metadata files (without their META-INF/ prefix) that should be added to the apk.
<assetsDirectory>directory</assetsDirectory> (default = ${project.basedir}/assets)
The directory that contains the assets to be added to the apk.
<attachJar>boolean</attachJar> (-Dandroid.attachJar=boolean) (default = true)
Specifies whether to attach the intermediary jar to the build. Currently ignored.
<attachSources>boolean</attachSources> (-Dandroid.attachSources=boolean) (default = false)
Specifies whether to attach the sources to the build. Currently ignored.
<combinedAssets>directory</combinedAssets> (default = ${project.build.directory}/generated-sources/combined-assets/assets)
The temporary directory in which asset files are collected before they are packaged.
<configurations>string</configurations> (-Dandroid.configurations=string)
A comma-separated list of configurations that aapt should include in the apk.
<dex>dex_configuration</dex>
Containing element for the following dex parameters.
<coreLibrary>boolean</coreLibrary> (-Dandroid.dex.coreLibrary=boolean) (default = false)
Specifies whether a core library is being compiled. Currently ignored.
<noLocals>boolean</noLocals> (-Dandroid.dex.noLocals=boolean) (default = false)
Specified whether the Dalvik bytecode should include debug information about local variables. Currently ignored.
<optimize>boolean</optimize> (-Dandroid.dex.optimize=boolean) (default = true)
Specifies whether the Dalvik bytecode should not be optimized. Currently ignored.
<excludeJarResources>string[]</excludeJarResources>
Patterns for names of jar files whose resources should not be added to the apk.
<extractDuplicates>boolean</extractDuplicates> (-Dandroid.extractDuplicates=boolean) (default = false)
Extracts duplicate files from embedded jars. Currently ignored.
<extractedDependenciesAssets>directory</extractedDependenciesAssets> (default = ${project.build.directory}/generated-sources/extracted-dependencies/assets)
A temporary directory for extracted asset files.
<extractedDependenciesDirectory>directory</extractedDependenciesDirectory> (default = ${project.build.directory}/generated-sources/extracted-dependencies)
A temporary directory for extracted files.
<extractedDependenciesJavaResources>directory</extractedDependenciesJavaResources> (default = ${project.build.directory}/generated-sources/extracted-dependencies/src/main/resources)
A temporary directory for extracted java resource files.
<extractedDependenciesJavaSources>directory</extractedDependenciesJavaSources> (default = ${project.build.directory}/generated-sources/extracted-dependencies/src/main/java)
A temporary directory for extracted java files.
<extractedDependenciesRes>directory</extractedDependenciesRes> (default = ${project.build.directory}/generated-sources/extracted-dependencies/res)
A temporary directory for extracted resource files.
<generateApk>boolean</generateApk> (-Dandroid.generateApk=boolean) (default = true)
Specifies whether to generate an apk file. Currently ignored.
<nativeLibrariesDependenciesHardwareArchitectureDefault>string</nativeLibrariesDependenciesHardwareArchitectureDefault> (-Dandroid.nativeLibrariesDependenciesHardwareArchitectureDefault=string) (default = armeabi)
The default hardware architecture for native libraries.
<nativeLibrariesDirectory>directory</nativeLibrariesDirectory> (-Dandroid.nativeLibrariesDirectory=directory) (default = ${project.basedir}/libs)
The root directory containing native libraries.
<ndkOutputDirectory>directory</ndkOutputDirectory> (default = ${project.build.directory}/ndk-libs)
The temporary directory in which native libraries are collected before they are packaged.
<proguard>proguard_configuration</proguard>
Containing element for the following ProGuard parameters.
<skip>boolean</skip> (-Dandroid.proguard.skip=boolean)
Specifies whether to skip shrinking, optimization, and obfuscation. The default is true for debug builds, and false for release builds.
<includeJdkLibs>boolean</includeJdkLibs> (-Dandroid.proguard.includeJdkLibs=boolean) (default = false)
Specifies whether the Java runtime libraries should be considered as library jars. Currently ignored.
<filterManifest>boolean</filterManifest> (-Dandroid.proguard.filterManifest=boolean) (default = false)
Specifies whether to filter out manifest files from the input.
<filterMavenDescriptor>boolean</filterMavenDescriptor> (-Dandroid.proguard.filterMavenDescriptor=boolean) (default = false)
Specifies whether to filter out Maven metadata files from the input.
<outputDirectory>directory</outputDirectory> (-Dandroid.proguard.outputDirectory=directory) (default = proguard)
The output directory for the Dexuard log files (seeds.txt, usage.txt, and mapping.txt).
<config>file</config> (-Dandroid.proguard.config=file)
The name of the optional ProGuard configuration file, relative to the project directory.
<proguardSkip>boolean</proguardSkip> (-Dandroid.proguard.skip=boolean)
Specifies whether to skip shrinking, optimization, and obfuscation. The default is true for debug builds, and false for release builds.
<includeJdkLibs>boolean</includeJdkLibs> (-Dandroid.proguard.includeJdkLibs=boolean) (default = false)
Specifies whether the Java runtime libraries should be considered as library jars. Currently ignored.
<proguardFilterManifest>boolean</proguardFilterManifest> (-Dandroid.proguard.filterManifest=boolean) (default = false)
Specifies whether to filter out manifest files from the input.
<proguardFilterMavenDescriptor>boolean</proguardFilterMavenDescriptor> (-Dandroid.proguard.filterMavenDescriptor=boolean) (default = false)
Specifies whether to filter out Maven metadata files from the input.
<outputDirectory>directory</outputDirectory> (-Dandroid.proguard.outputDirectory=directory) (default = proguard)
The output directory for the Dexuard log files (seeds.txt, usage.txt, and mapping.txt).
<proguardConfig>file</proguardConfig> (-Dandroid.proguard.config=file)
The name of the optional ProGuard configuration file, relative to the project directory.
<proguardConfigs>file[]</proguardConfigs> (-Dandroid.proguard.config=file[])
The name of the optional ProGuard configuration files, relative to the project directory.
<proguardOptions>string[]</proguardOptions> (-Dandroid.proguard.options=string[])
Additional ProGuard/DexGuard options.
<proguardConfig>file</proguarCconfig> (-Dandroid.proguard.config=file)
The name of the optional ProGuard configuration file, relative to the project directory.
<proguardConfigs>file[]</proguardConfigs> (-Dandroid.proguard.config=file[])
The name of the optional ProGuard configuration files, relative to the project directory.
<proguardOptions>string[]</proguardOptions> (-Dandroid.proguard.options=string[])
Additional ProGuard/DexGuard options.
<dexguardConfig>file</dexguardConfig> (-Dandroid.dexguard.config=file) (default = dexguard-project.txt)
The name of the optional DexGuard configuration file, relative to the project directory.
<dexguardConfigs>file[]</dexguardConfigs> (-Dandroid.dexguard.configs=file[])
Alternative DexGuard configuration files, relative to the project directory.
<release>boolean</release> (-Dandroid.release=boolean) (default = false)
Specifies whether this is a release build, as opposed to a debug build.
<renameInstrumentationTargetPackage>string</renameInstrumentationTargetPackage> (-Dandroid.renameInstrumentationTargetPackage=string)
The package that aapt should let instrumentation components target.
<renameManifestPackage>string</renameManifestPackage> (-Dandroid.renameManifestPackage=string)
The package name that aapt should set on the application.
<resourceDirectory>directory</resourceDirectory> (default = ${project.basedir}/res)
The directory that contains the resource files.
<resourceOverlayDirectories>directory[]</resourceOverlayDirectories>
Directories that contain resource overlay files.
<resourceOverlayDirectory>directory</resourceOverlayDirectory> (default = ${project.basedir}/res-overlay)
The default directory that contains resource overlay files.
<sdk>sdk_configuration</sdk>
Containing element for the following Android SDK parameters.
<path>directory</path> (-Dandroid.sdk.path=directory) (ANDROID_SDK=directory)
The path to the Android SDK.
<platform>string</platform> (-Dandroid.sdk.platform=string)
The Android platform against which to build (1.1, 1.5, etc., or 3, 4, etc.)
<sign>signing_configuration</sign>
Containing element for the following signing parameters.
<debug>string</debug> (-Dandroid.sign.debug=string) (default = auto)
Specifies whether the apk should be signed with the debug keystore (true, false, or auto).
<keystore>file</keystore> (-Dandroid.sign.keystore=file)
The key store to sign processed applications.
<storepass>string</storepass> (-Dandroid.sign.storepass=string)
The password of the key store.
<alias>string</alias> (-Dandroid.sign.alias=string)
The key alias.
<keypass>string</keypass> (-Dandroid.sign.keypass=string)
The password of the key.
<sourceDirectories>directory[]</sourceDirectories> (-Dandroid.sourceDirectories=directory[])
Additional source directories that contain resource files to be packaged in the apk.
<outputApk>file</outputApk> (-Dandroid.outputApk=file) (default = ${project.build.directory}/${project.build.finalName}.apk)
The name of the created apk.

Quick troubleshooting

If you are having problems running the Maven plugin:

Please consult the more extensive troubleshooting section if you encounter other issues building or running your application.


Copyright © 2002-2014 Saikoa BVBA.