android:apk

Full name:

com.jayway.maven.plugins.android.generation2:android-maven-plugin:3.5.3:apk

Description:

Creates the apk file. By default signs it with debug keystore.
Change that by setting configuration parameter <sign><debug>false</debug></sign>.

Attributes:

  • Requires a Maven project to be executed.
  • Requires dependency resolution of artifacts in scope: compile.
  • Binds by default to the lifecycle phase: package.

Optional Parameters

Name Type Since Description
aaptExtraArgs String[] - A list of extra arguments that must be passed to aapt.
androidManifestFile File - The AndroidManifest.xml file.
Default value is: ${project.basedir}/AndroidManifest.xml.
apk Apk - Embedded configuration of this mojo.
apkDebug Boolean - Defines whether or not the APK is being produced in debug mode or not.
apkMetaIncludes String[] - Pattern for additional META-INF resources to be packaged into the apk.

The APK builder filters these resources and doesn't include them into the apk. This leads to bad behaviour of dependent libraries relying on these resources, for instance service discovery doesn't work.
By specifying this pattern, the android plugin adds these resources to the final apk.

The pattern is relative to META-INF, i.e. one must use


<apkMetaIncludes>
    <metaInclude>services/**</metaInclude>
</apkMetaIncludes>

... instead of

<apkMetaIncludes>
    <metaInclude>META-INF/services/**</metaInclude>
</apkMetaIncludes>

See also Issue 97


apkNativeToolchain String - (no description)
assetsDirectory File - The android assets directory.
Default value is: ${project.basedir}/assets.
attachJar boolean -

Whether to attach the normal .jar file to the build, so it can be depended on by for example integration-tests which may then access R.java from this project.

Only disable it if you know you won't need it for any integration-tests. Otherwise, leave it enabled.


Default value is: true.
attachSources boolean -

Whether to attach sources to the build, which can be depended on by other apk projects, for including them in their builds.

Enabling this setting is only required if this project's source code and/or res(ources) will be included in other projects, using the Maven <dependency> tag.


Default value is: false.
classifier String -

Classifier to add to the artifact generated. If given, the artifact will be an attachment instead.


configurations String - A selection of configurations to be included in the APK as a comma separated list. This will limit the configurations for a certain type. For example, specifying hdpi will exclude all resource folders with the mdpi or ldpi modifiers, but won't affect language or orientation modifiers. For more information about this option, look in the aapt command line help.
customPackage String - Generates R.java into a different package.
device String - Specifies which the serial number of the device to connect to. Using the special values "usb" or "emulator" is also valid. "usb" will connect to all actual devices connected (via usb). "emulator" will connect to all emulators connected. Multiple devices will be iterated over in terms of goals to run. All device interaction goals support this so you can e.. deploy the apk to all attached emulators and devices. Goals supporting this are devices, deploy, undeploy, redeploy, pull, push and instrument.
excludeJarResources String[] - Specify a list of patterns that are matched against the names of jar file dependencies. Matching jar files will not have their resources added to the resulting APK. The patterns are standard Java regexes.
extractDuplicates boolean -

Allows to detect and extract the duplicate files from embedded jars. In that case, the plugin analyzes the content of all embedded dependencies and checks they are no duplicates inside those dependencies. Indeed, Android does not support duplicates, and all dependencies are inlined in the APK. If duplicates files are found, the resource is kept in the first dependency and removes from others.


Default value is: false.
generateApk boolean - Decides whether the Apk should be generated or not. If set to false, dx and apkBuilder will not run. This is probably most useful for a project used to generate apk sources to be inherited into another application project.
Default value is: true.
nativeLibrariesDirectory File -

Root folder containing native libraries to include in the application package.


Default value is: ${project.basedir}/libs.
ndk Ndk -

The Android NDK to use.

Looks like this:

<ndk>
    <path>/opt/android-ndk-r4</path>
</ndk>

The <path> parameter is optional. The default is the setting of the ANDROID_NDK_HOME environment variable. The parameter can be used to override this setting with a different environment variable like this:

<ndk>
    <path>${env.ANDROID_NDK_HOME}</path>
</ndk>

or just with a hardcoded absolute path. The parameters can also be configured from command-line with parameter -Dandroid.ndk.path.


ndkFinalLibraryName String - Specifies the final name of the library output by the build (this allows
proguardFile File - Automatically create a ProGuard configuration file that will guard Activity classes and the like that are defined in the AndroidManifest.xml. This files is then automatically used in the proguard mojo execution, if enabled.
release boolean - Whether to create a release build (default is false / debug build). This affect BuildConfig generation and apk generation at this stage, but should probably affect other aspects of the build.
Default value is: false.
renameInstrumentationTargetPackage String -

Rewrite the manifest so that all of its instrumentation components target the given package. This value will be passed on to the aapt parameter --rename-instrumentation-target-package. Look to aapt for more help on this.


renameManifestPackage String -

A possibly new package name for the application. This value will be passed on to the aapt parameter --rename-manifest-package. Look to aapt for more help on this.


resourceDirectory File - The android resources directory.
Default value is: ${project.basedir}/res.
resourceOverlayDirectories File[] - The android resources overlay directories. If this is specified, the resourceOverlayDirectory parameter will be ignored.
resourceOverlayDirectory File - The android resources overlay directory. This will be overridden by resourceOverlayDirectories if present.
Default value is: ${project.basedir}/res-overlay.
sdk Sdk -

The Android SDK to use.

Looks like this:

<sdk>
    <path>/opt/android-sdk-linux</path>
    <platform>2.1</platform>
</sdk>

The <platform> parameter is optional, and corresponds to the platforms/android-* directories in the Android SDK directory. Default is the latest available version, so you only need to set it if you for example want to use platform 1.5 but also have e.g. 2.2 installed. Has no effect when used on an Android SDK 1.1. The parameter can also be coded as the API level. Therefore valid values are 1.1, 1.5, 1.6, 2.0, 2.01, 2.1, 2.2 and so as well as 3, 4, 5, 6, 7, 8... 16. If a platform/api level is not installed on the machine an error message will be produced.

The <path> parameter is optional. The default is the setting of the ANDROID_HOME environment variable. The parameter can be used to override this setting with a different environment variable like this:

<sdk>
    <path>${env.ANDROID_SDK}</path>
</sdk>

or just with a hard-coded absolute path. The parameters can also be configured from command-line with parameters -Dandroid.sdk.path and -Dandroid.sdk.platform.


sign Sign -

How to sign the apk.

Looks like this:

<sign>
    <debug>auto</debug>
</sign>

Valid values for <debug> are:

  • true = sign with the debug keystore.
  • false = don't sign with the debug keystore.
  • both = create a signed as well as an unsigned apk.
  • auto (default) = sign with debug keystore, unless another keystore is defined. (Signing with other keystores is not yet implemented. See Issue 2.)


Can also be configured from command-line with parameter -Dandroid.sign.debug.


sourceDirectories File[] -

Additional source directories that contain resources to be packaged into the apk.

These are not source directories, that contain java classes to be compiled. It corresponds to the -df option of the apkbuilder program. It allows you to specify directories, that contain additional resources to be packaged into the apk.

So an example inside the plugin configuration could be:
<configuration>
  ...
   <sourceDirectories>
     <sourceDirectory>${project.basedir}/additionals</sourceDirectory>
  </sourceDirectories>
  ...
</configuration>

undeployBeforeDeploy boolean -

Whether to undeploy an apk from the device before deploying it.

Only has effect when running mvn android:deploy in an Android application project manually, or when running mvn integration-test (or mvn install) in a project with instrumentation tests.

It is useful to keep this set to true at all times, because if an apk with the same package was previously signed with a different keystore, and deployed to the device, deployment will fail becuase your keystore is different.


Default value is: false.

Parameter Details

aaptExtraArgs:

A list of extra arguments that must be passed to aapt.
  • Type: java.lang.String[]
  • Required: No
  • Expression: ${android.aaptExtraArgs}

androidManifestFile:

The AndroidManifest.xml file.
  • Type: java.io.File
  • Required: No
  • Default: ${project.basedir}/AndroidManifest.xml

apk:

Embedded configuration of this mojo.
  • Type: com.jayway.maven.plugins.android.configuration.Apk
  • Required: No

apkDebug:

Defines whether or not the APK is being produced in debug mode or not.
  • Type: java.lang.Boolean
  • Required: No
  • Expression: ${android.apk.debug}

apkMetaIncludes:

Pattern for additional META-INF resources to be packaged into the apk.

The APK builder filters these resources and doesn't include them into the apk. This leads to bad behaviour of dependent libraries relying on these resources, for instance service discovery doesn't work.
By specifying this pattern, the android plugin adds these resources to the final apk.

The pattern is relative to META-INF, i.e. one must use


<apkMetaIncludes>
    <metaInclude>services/**</metaInclude>
</apkMetaIncludes>

... instead of

<apkMetaIncludes>
    <metaInclude>META-INF/services/**</metaInclude>
</apkMetaIncludes>

See also Issue 97

  • Type: java.lang.String[]
  • Required: No
  • Expression: ${android.apk.metaIncludes}

apkNativeToolchain:

(no description)
  • Type: java.lang.String
  • Required: No
  • Expression: ${android.nativeToolchain}

assetsDirectory:

The android assets directory.
  • Type: java.io.File
  • Required: No
  • Default: ${project.basedir}/assets

attachJar:

Whether to attach the normal .jar file to the build, so it can be depended on by for example integration-tests which may then access R.java from this project.

Only disable it if you know you won't need it for any integration-tests. Otherwise, leave it enabled.

  • Type: boolean
  • Required: No
  • Expression: ${android.attachJar}
  • Default: true

attachSources:

Whether to attach sources to the build, which can be depended on by other apk projects, for including them in their builds.

Enabling this setting is only required if this project's source code and/or res(ources) will be included in other projects, using the Maven <dependency> tag.

  • Type: boolean
  • Required: No
  • Expression: ${android.attachSources}
  • Default: false

classifier:

Classifier to add to the artifact generated. If given, the artifact will be an attachment instead.

  • Type: java.lang.String
  • Required: No

configurations:

A selection of configurations to be included in the APK as a comma separated list. This will limit the configurations for a certain type. For example, specifying hdpi will exclude all resource folders with the mdpi or ldpi modifiers, but won't affect language or orientation modifiers. For more information about this option, look in the aapt command line help.
  • Type: java.lang.String
  • Required: No
  • Expression: ${android.configurations}

customPackage:

Generates R.java into a different package.
  • Type: java.lang.String
  • Required: No
  • Expression: ${android.customPackage}

device:

Specifies which the serial number of the device to connect to. Using the special values "usb" or "emulator" is also valid. "usb" will connect to all actual devices connected (via usb). "emulator" will connect to all emulators connected. Multiple devices will be iterated over in terms of goals to run. All device interaction goals support this so you can e.. deploy the apk to all attached emulators and devices. Goals supporting this are devices, deploy, undeploy, redeploy, pull, push and instrument.
  • Type: java.lang.String
  • Required: No
  • Expression: ${android.device}

excludeJarResources:

Specify a list of patterns that are matched against the names of jar file dependencies. Matching jar files will not have their resources added to the resulting APK. The patterns are standard Java regexes.
  • Type: java.lang.String[]
  • Required: No

extractDuplicates:

Allows to detect and extract the duplicate files from embedded jars. In that case, the plugin analyzes the content of all embedded dependencies and checks they are no duplicates inside those dependencies. Indeed, Android does not support duplicates, and all dependencies are inlined in the APK. If duplicates files are found, the resource is kept in the first dependency and removes from others.

  • Type: boolean
  • Required: No
  • Expression: ${android.extractDuplicates}
  • Default: false

generateApk:

Decides whether the Apk should be generated or not. If set to false, dx and apkBuilder will not run. This is probably most useful for a project used to generate apk sources to be inherited into another application project.
  • Type: boolean
  • Required: No
  • Expression: ${android.generateApk}
  • Default: true

nativeLibrariesDirectory:

Root folder containing native libraries to include in the application package.

  • Type: java.io.File
  • Required: No
  • Expression: ${android.nativeLibrariesDirectory}
  • Default: ${project.basedir}/libs

ndk:

The Android NDK to use.

Looks like this:

<ndk>
    <path>/opt/android-ndk-r4</path>
</ndk>

The <path> parameter is optional. The default is the setting of the ANDROID_NDK_HOME environment variable. The parameter can be used to override this setting with a different environment variable like this:

<ndk>
    <path>${env.ANDROID_NDK_HOME}</path>
</ndk>

or just with a hardcoded absolute path. The parameters can also be configured from command-line with parameter -Dandroid.ndk.path.

  • Type: com.jayway.maven.plugins.android.configuration.Ndk
  • Required: No

ndkFinalLibraryName:

Specifies the final name of the library output by the build (this allows
  • Type: java.lang.String
  • Required: No
  • Expression: ${android.ndk.build.build.final-library.name}

proguardFile:

Automatically create a ProGuard configuration file that will guard Activity classes and the like that are defined in the AndroidManifest.xml. This files is then automatically used in the proguard mojo execution, if enabled.
  • Type: java.io.File
  • Required: No
  • Expression: ${android.proguardFile}

release:

Whether to create a release build (default is false / debug build). This affect BuildConfig generation and apk generation at this stage, but should probably affect other aspects of the build.
  • Type: boolean
  • Required: No
  • Expression: ${android.release}
  • Default: false

renameInstrumentationTargetPackage:

Rewrite the manifest so that all of its instrumentation components target the given package. This value will be passed on to the aapt parameter --rename-instrumentation-target-package. Look to aapt for more help on this.

  • Type: java.lang.String
  • Required: No
  • Expression: ${android.renameInstrumentationTargetPackage}

renameManifestPackage:

A possibly new package name for the application. This value will be passed on to the aapt parameter --rename-manifest-package. Look to aapt for more help on this.

  • Type: java.lang.String
  • Required: No
  • Expression: ${android.renameManifestPackage}

resourceDirectory:

The android resources directory.
  • Type: java.io.File
  • Required: No
  • Default: ${project.basedir}/res

resourceOverlayDirectories:

The android resources overlay directories. If this is specified, the resourceOverlayDirectory parameter will be ignored.
  • Type: java.io.File[]
  • Required: No

resourceOverlayDirectory:

The android resources overlay directory. This will be overridden by resourceOverlayDirectories if present.
  • Type: java.io.File
  • Required: No
  • Default: ${project.basedir}/res-overlay

sdk:

The Android SDK to use.

Looks like this:

<sdk>
    <path>/opt/android-sdk-linux</path>
    <platform>2.1</platform>
</sdk>

The <platform> parameter is optional, and corresponds to the platforms/android-* directories in the Android SDK directory. Default is the latest available version, so you only need to set it if you for example want to use platform 1.5 but also have e.g. 2.2 installed. Has no effect when used on an Android SDK 1.1. The parameter can also be coded as the API level. Therefore valid values are 1.1, 1.5, 1.6, 2.0, 2.01, 2.1, 2.2 and so as well as 3, 4, 5, 6, 7, 8... 16. If a platform/api level is not installed on the machine an error message will be produced.

The <path> parameter is optional. The default is the setting of the ANDROID_HOME environment variable. The parameter can be used to override this setting with a different environment variable like this:

<sdk>
    <path>${env.ANDROID_SDK}</path>
</sdk>

or just with a hard-coded absolute path. The parameters can also be configured from command-line with parameters -Dandroid.sdk.path and -Dandroid.sdk.platform.

  • Type: com.jayway.maven.plugins.android.configuration.Sdk
  • Required: No

sign:

How to sign the apk.

Looks like this:

<sign>
    <debug>auto</debug>
</sign>

Valid values for <debug> are:

  • true = sign with the debug keystore.
  • false = don't sign with the debug keystore.
  • both = create a signed as well as an unsigned apk.
  • auto (default) = sign with debug keystore, unless another keystore is defined. (Signing with other keystores is not yet implemented. See Issue 2.)


Can also be configured from command-line with parameter -Dandroid.sign.debug.

  • Type: com.jayway.maven.plugins.android.configuration.Sign
  • Required: No

sourceDirectories:

Additional source directories that contain resources to be packaged into the apk.

These are not source directories, that contain java classes to be compiled. It corresponds to the -df option of the apkbuilder program. It allows you to specify directories, that contain additional resources to be packaged into the apk.

So an example inside the plugin configuration could be:
<configuration>
  ...
   <sourceDirectories>
     <sourceDirectory>${project.basedir}/additionals</sourceDirectory>
  </sourceDirectories>
  ...
</configuration>
  • Type: java.io.File[]
  • Required: No
  • Expression: ${android.sourceDirectories}

undeployBeforeDeploy:

Whether to undeploy an apk from the device before deploying it.

Only has effect when running mvn android:deploy in an Android application project manually, or when running mvn integration-test (or mvn install) in a project with instrumentation tests.

It is useful to keep this set to true at all times, because if an apk with the same package was previously signed with a different keystore, and deployed to the device, deployment will fail becuase your keystore is different.

  • Type: boolean
  • Required: No
  • Expression: ${android.undeployBeforeDeploy}
  • Default: false