public abstract class AbstractAndroidMojo
extends org.apache.maven.plugin.AbstractMojo
Modifier and Type | Field and Description |
---|---|
protected String[] |
aaptExtraArgs
A list of extra arguments that must be passed to aapt.
|
protected boolean |
aaptVerbose
Activate verbose output for the aapt execution in Maven debug mode.
|
protected int |
adbConnectionTimeout
The timeout value for an adb connection in milliseconds.
|
protected File |
androidManifestFile
The
AndroidManifest.xml file. |
protected File |
assetsDirectory
The android assets directory.
|
protected boolean |
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. |
protected boolean |
attachSources
Whether to attach sources to the build, which can be depended on by other
apk projects, for including
them in their builds. |
protected File |
combinedAssets
The combined assets directory.
|
protected String |
configurations
A selection of configurations to be included in the APK as a comma separated list.
|
protected String |
customPackage
Generates R.java into a different package.
|
protected org.apache.maven.shared.dependency.graph.DependencyGraphBuilder |
dependencyGraphBuilder
Dependency graph builder component.
|
protected File |
destinationManifestFile
Path to which to save the result of updating/merging/processing the source
AndroidManifest.xml
file (androidManifestFile ). |
protected String |
device
Specifies which the serial number of the device to connect to.
|
protected String[] |
devices
Specifies a list of serial numbers of each device you want to connect to.
|
protected int |
deviceThreads
Specifies the number of threads to use for deploying and testing on attached devices.
|
static String |
ENV_ANDROID_HOME
The
ANDROID_HOME environment variable name. |
static String |
ENV_ANDROID_NDK_HOME
The
ANDROID_NDK_HOME environment variable name. |
protected org.apache.maven.plugin.MojoExecution |
execution |
protected File |
extractedDependenciesDirectory |
protected File |
extractedDependenciesJavaResources |
protected File |
extractedDependenciesJavaSources |
protected String |
finalName
The final name of the artifact.
|
protected File |
genDirectory
Override default generated folder containing R.java
|
protected boolean |
generateApk
Decides whether the Apk should be generated or not.
|
protected String[] |
ips
External IP addresses.
|
protected File |
nativeLibrariesDirectory
Root folder containing native libraries to include in the application package.
|
protected File |
ndkOutputDirectory
Folder in which the ndk libraries are collected ready for packaging.
|
protected File |
proguardFile
Automatically create a ProGuard configuration file that will guard Activity classes and the like that are
defined in the AndroidManifest.xml.
|
protected org.apache.maven.project.MavenProject |
project
The maven project.
|
protected org.apache.maven.project.MavenProjectHelper |
projectHelper
Maven ProjectHelper.
|
protected File |
projectOutputDirectory
The output directory.
|
protected boolean |
release
Whether to create a release build (default is false / debug build).
|
protected String |
renameManifestPackage
A possibly new package name for the application.
|
protected File |
resourceDirectory
The Android resources (src/main/res) directory.
|
protected File[] |
resourceOverlayDirectories
The android resources overlay directories.
|
protected File |
resourceOverlayDirectory
The android resources overlay directory.
|
protected List<org.apache.maven.model.Resource> |
resources
The project resources.
|
protected org.apache.maven.execution.MavenSession |
session
The maven session.
|
protected File |
sourceDirectory
The java sources directory.
|
protected String |
sourceEncoding
The project source encoding.
|
static List<String> |
SUPPORTED_PACKAGING_TYPES |
protected File |
targetDirectory
The project build directory.
|
protected boolean |
undeployBeforeDeploy
Whether to undeploy an apk from the device before deploying it.
|
Constructor and Description |
---|
AbstractAndroidMojo() |
Modifier and Type | Method and Description |
---|---|
protected void |
copyFolder(File sourceFolder,
File targetFolder)
Copies the files contained within the source folder to the target folder.
|
protected void |
deployApk(File apkFile)
Deploys an apk file to a connected emulator or usb device.
|
protected void |
deployBuiltApk()
Deploy the apk built with the current projects to all attached devices and emulators.
|
protected void |
deployDependencies() |
protected void |
doWithDevices(DeviceCallback deviceCallback)
Performs the callback action on the devices determined by
shouldDoWithThisDevice(com.android.ddmlib.IDevice) |
protected String |
extractInstrumentationRunnerFromAndroidManifest(File manifestFile)
Attempts to find the instrumentation test runner from inside the AndroidManifest.xml file.
|
protected String |
extractPackageNameFromAndroidArtifact(org.apache.maven.artifact.Artifact artifact)
Provides package name for android artifact.
|
protected String |
extractPackageNameFromAndroidManifest(File manifestFile) |
protected String |
extractPackageNameFromAndroidManifestXmlTree(String aaptDumpXmlTree)
Extracts the package name from an XmlTree dump of AndroidManifest.xml by the
aapt tool. |
protected String |
extractPackageNameFromApk(File apkFile)
Extracts the package name from an apk file.
|
protected String |
getAndroidManifestPackageName() |
protected AndroidNdk |
getAndroidNdk()
Returns the Android NDK to use.
|
protected AndroidSdk |
getAndroidSdk()
Returns the Android SDK to use.
|
protected ArtifactResolverHelper |
getArtifactResolverHelper() |
protected DependencyResolver |
getDependencyResolver() |
protected Set<org.apache.maven.artifact.Artifact> |
getDirectDependencyArtifacts() |
protected Jack |
getJack() |
static File |
getLibraryUnpackDirectory(File unpackedApkLibsDirectory,
org.apache.maven.artifact.Artifact artifact) |
protected NativeHelper |
getNativeHelper() |
protected Set<org.apache.maven.artifact.Artifact> |
getRelevantCompileArtifacts() |
File[] |
getResourceOverlayDirectories() |
protected Set<org.apache.maven.artifact.Artifact> |
getTransitiveDependencyArtifacts(List<String> filteredScopes,
String... types)
Provides transitive dependency artifacts only defined types based on
types argument
or all types if types argument is empty |
protected Set<org.apache.maven.artifact.Artifact> |
getTransitiveDependencyArtifacts(String... types)
Provides transitive dependency artifacts having types defined by
types argument
or all types if types argument is empty |
protected File |
getUnpackedAarClassesJar(org.apache.maven.artifact.Artifact artifact) |
protected File |
getUnpackedApkLibSourceFolder(org.apache.maven.artifact.Artifact artifact) |
protected File |
getUnpackedLibAssetsFolder(org.apache.maven.artifact.Artifact artifact) |
File |
getUnpackedLibFolder(org.apache.maven.artifact.Artifact artifact) |
protected UnpackedLibHelper |
getUnpackedLibHelper() |
File |
getUnpackedLibNativesFolder(org.apache.maven.artifact.Artifact artifact) |
protected File |
getUnpackedLibResourceFolder(org.apache.maven.artifact.Artifact artifact) |
protected File |
getUnpackedLibsDirectory() |
protected com.android.ddmlib.AndroidDebugBridge |
initAndroidDebugBridge()
Initialize the Android Debug Bridge and wait for it to start.
|
protected boolean |
isAPKBuild() |
protected boolean |
isInstrumentationTest() |
protected File |
resolveArtifactToFile(org.apache.maven.artifact.Artifact artifact)
Attempts to resolve an
Artifact to a File . |
protected boolean |
undeployApk(File apkFile)
Undeploys an apk from a connected emulator or usb device.
|
protected boolean |
undeployApk(String packageName)
Undeploys an apk, specified by package name, from a connected emulator
or usb device.
|
protected void |
waitForInitialDeviceList(com.android.ddmlib.AndroidDebugBridge androidDebugBridge)
Wait for the Android Debug Bridge to return an initial device list.
|
getLog, getPluginContext, setLog, setPluginContext
public static final String ENV_ANDROID_NDK_HOME
ANDROID_NDK_HOME
environment variable name.@Component protected org.apache.maven.project.MavenProject project
@Component protected org.apache.maven.execution.MavenSession session
@Component protected org.apache.maven.plugin.MojoExecution execution
@Parameter(defaultValue="${project.build.sourceDirectory}", readonly=true) protected File sourceDirectory
@Parameter(defaultValue="${project.build.directory}", readonly=true) protected File targetDirectory
@Parameter(defaultValue="${project.build.outputDirectory}", readonly=true) protected File projectOutputDirectory
@Parameter(defaultValue="${project.build.resources}", readonly=true) protected List<org.apache.maven.model.Resource> resources
@Parameter(defaultValue="${project.build.finalName}", readonly=true) protected String finalName
@Parameter(defaultValue="${project.basedir}/src/main/res") protected File resourceDirectory
@Parameter(defaultValue="${project.build.sourceEncoding}", readonly=true) protected String sourceEncoding
@Parameter(property="android.genDirectory", defaultValue="${project.build.directory}/generated-sources/r") protected File genDirectory
@Parameter(property="android.nativeLibrariesDirectory", defaultValue="${project.basedir}/src/main/libs") protected File nativeLibrariesDirectory
Root folder containing native libraries to include in the application package.
@Parameter(defaultValue="${project.build.directory}/ndk-libs", readonly=true) protected File ndkOutputDirectory
@Parameter(defaultValue="${project.basedir}/res-overlay") protected File resourceOverlayDirectory
@Parameter protected File[] resourceOverlayDirectories
resourceOverlayDirectory
parameter will be ignored.@Parameter(defaultValue="${project.basedir}/src/main/assets") protected File assetsDirectory
@Parameter(property="android.manifestFile", defaultValue="${project.basedir}/src/main/AndroidManifest.xml") protected File androidManifestFile
AndroidManifest.xml
file.@Parameter(property="destination.manifestFile", defaultValue="${project.build.directory}/AndroidManifest.xml") protected File destinationManifestFile
AndroidManifest.xml
file (androidManifestFile
).@Parameter(property="android.renameManifestPackage") protected String 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.
@Parameter(defaultValue="${project.build.directory}/generated-sources/extracted-dependencies", readonly=true) protected File extractedDependenciesDirectory
@Parameter(defaultValue="${project.build.directory}/generated-sources/extracted-dependencies/src/main/java", readonly=true) protected File extractedDependenciesJavaSources
@Parameter(defaultValue="${project.build.directory}/generated-sources/extracted-dependencies/src/main/resources", readonly=true) protected File extractedDependenciesJavaResources
@Parameter(defaultValue="${project.build.directory}/generated-sources/combined-assets", readonly=true) protected File combinedAssets
@Parameter(property="android.device") protected String device
@Parameter(property="android.devices") protected String[] devices
Specifies a list of serial numbers of each device you want 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.
<devices> <device>usb</device> <device>emulator-5554</device> </devices>
This parameter can also be configured from command-line with
parameter -Dandroid.devices=usb,emulator
.
@Parameter(property="android.deviceThreads") protected int deviceThreads
Specifies the number of threads to use for deploying and testing on attached devices.
This parameter can also be configured from command-line with
parameter -Dandroid.deviceThreads=2
.
@Parameter(property="android.ips") protected String[] ips
External IP addresses. The connect goal of the android maven plugin will execute an adb connect on each IP address. If you have external dervice, you should call this connect goal before any other goal : mvn clean android:connect install.
The Maven plugin will automatically add all these IP addresses into the the devices parameter. If you want to disconnect the IP addresses after the build, you can call the disconnect goal : mvn clean android:connect install android:disconnect
<ips> <ip>127.0.0.1:5556</ip> </ips>
@Parameter(property="android.configurations") protected String configurations
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.@Parameter(property="android.aaptExtraArgs") protected String[] aaptExtraArgs
@Parameter(property="android.aaptVerbose") protected boolean aaptVerbose
@Parameter(property="android.proguardFile") protected File proguardFile
@Parameter(property="android.generateApk", defaultValue="true") protected boolean generateApk
@Parameter(property="android.customPackage") protected String customPackage
@Component protected org.apache.maven.project.MavenProjectHelper projectHelper
public static final String ENV_ANDROID_HOME
ANDROID_HOME
environment variable name.@Parameter(property="android.undeployBeforeDeploy", defaultValue="false") protected boolean 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 because your
keystore is different.
@Parameter(property="android.attachJar", defaultValue="true") protected boolean 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.
@Parameter(property="android.attachSources", defaultValue="false") protected boolean 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.
@Parameter(property="android.release", defaultValue="false") protected boolean release
@Parameter(property="android.adb.connectionTimeout", defaultValue="5000") protected int adbConnectionTimeout
@Component(hint="default") protected org.apache.maven.shared.dependency.graph.DependencyGraphBuilder dependencyGraphBuilder
protected final DependencyResolver getDependencyResolver()
protected Set<org.apache.maven.artifact.Artifact> getRelevantCompileArtifacts()
Set
of dependencies which may be extracted and otherwise included in other artifacts. Never
null
. This excludes artifacts of the EXCLUDED_DEPENDENCY_SCOPES
scopes.protected Set<org.apache.maven.artifact.Artifact> getDirectDependencyArtifacts()
Set
of direct project dependencies. Never null
. This excludes artifacts of the EXCLUDED_DEPENDENCY_SCOPES
scopes.protected Set<org.apache.maven.artifact.Artifact> getTransitiveDependencyArtifacts(String... types)
types
argument
or all types if types
argument is emptytypes
- artifact types to be selectedList
of all project dependencies. Never null
.
This excludes artifacts of the ArtifactResolverHelper.EXCLUDE_NON_PACKAGED_SCOPES
scopes.
This should maintain dependency order to comply with library project resource precedence.protected Set<org.apache.maven.artifact.Artifact> getTransitiveDependencyArtifacts(List<String> filteredScopes, String... types)
types
argument
or all types if types
argument is emptyfilteredScopes
- List of scopes to be removed (ie filtered out).types
- Zero or more artifact types to be selected.List
of all project dependencies. Never null
.
This should maintain dependency order to comply with library project resource precedence.protected File resolveArtifactToFile(org.apache.maven.artifact.Artifact artifact) throws org.apache.maven.plugin.MojoExecutionException
Artifact
to a File
.artifact
- to resolveFile
to the resolved artifact, never null
.org.apache.maven.plugin.MojoExecutionException
- if the artifact could not be resolved.protected com.android.ddmlib.AndroidDebugBridge initAndroidDebugBridge() throws org.apache.maven.plugin.MojoExecutionException
org.apache.maven.plugin.MojoExecutionException
protected void waitForInitialDeviceList(com.android.ddmlib.AndroidDebugBridge androidDebugBridge) throws org.apache.maven.plugin.MojoExecutionException
org.apache.maven.plugin.MojoExecutionException
protected void deployApk(File apkFile) throws org.apache.maven.plugin.MojoExecutionException, org.apache.maven.plugin.MojoFailureException
apkFile
- the file to deployorg.apache.maven.plugin.MojoExecutionException
- If there is a problem deploying the apk file.org.apache.maven.plugin.MojoFailureException
protected void deployDependencies() throws org.apache.maven.plugin.MojoExecutionException, org.apache.maven.plugin.MojoFailureException
org.apache.maven.plugin.MojoExecutionException
org.apache.maven.plugin.MojoFailureException
protected void deployBuiltApk() throws org.apache.maven.plugin.MojoExecutionException, org.apache.maven.plugin.MojoFailureException
org.apache.maven.plugin.MojoExecutionException
org.apache.maven.plugin.MojoFailureException
protected void doWithDevices(DeviceCallback deviceCallback) throws org.apache.maven.plugin.MojoExecutionException, org.apache.maven.plugin.MojoFailureException
shouldDoWithThisDevice(com.android.ddmlib.IDevice)
deviceCallback
- the action to perform on each deviceorg.apache.maven.plugin.MojoExecutionException
- in case there is a problemorg.apache.maven.plugin.MojoFailureException
- in case there is a problemprotected boolean undeployApk(File apkFile) throws org.apache.maven.plugin.MojoExecutionException, org.apache.maven.plugin.MojoFailureException
apkFile
- the file to undeploytrue
if successfully undeployed, false
otherwise.org.apache.maven.plugin.MojoExecutionException
org.apache.maven.plugin.MojoFailureException
protected boolean undeployApk(String packageName) throws org.apache.maven.plugin.MojoExecutionException, org.apache.maven.plugin.MojoFailureException
packageName
- the package name to undeploy.true
if successfully undeployed, false
otherwise.org.apache.maven.plugin.MojoExecutionException
org.apache.maven.plugin.MojoFailureException
protected String extractPackageNameFromApk(File apkFile) throws org.apache.maven.plugin.MojoExecutionException
apkFile
- apk file to extract package name from.org.apache.maven.plugin.MojoExecutionException
protected String extractPackageNameFromAndroidManifestXmlTree(String aaptDumpXmlTree)
aapt
tool.aaptDumpXmlTree
- output from aapt dump xmltree <apkFile> AndroidManifest.xml
protected String extractPackageNameFromAndroidArtifact(org.apache.maven.artifact.Artifact artifact) throws org.apache.maven.plugin.MojoExecutionException
artifact
- android artifact which package have to be extractedorg.apache.maven.plugin.MojoExecutionException
- if there is no AndroidManifest.xml for provided artifact
or appears error while parsing in extractPackageNameFromAndroidManifest(File)
extractPackageNameFromAndroidManifest(File)
protected String extractPackageNameFromAndroidManifest(File manifestFile)
protected final String getAndroidManifestPackageName()
protected String extractInstrumentationRunnerFromAndroidManifest(File manifestFile) throws org.apache.maven.plugin.MojoExecutionException
manifestFile
- the AndroidManifest.xml file to inspect.null
if it is not declared.org.apache.maven.plugin.MojoExecutionException
protected final boolean isInstrumentationTest() throws org.apache.maven.plugin.MojoExecutionException
org.apache.maven.plugin.MojoExecutionException
protected AndroidSdk getAndroidSdk() throws org.apache.maven.plugin.MojoExecutionException
Returns the Android SDK to use.
Current implementation looks for System property android.sdk.path
, then
<sdk><path>
configuration in pom, then environment variable ANDROID_HOME
.
This is where we collect all logic for how to lookup where it is, and which one to choose. The lookup is based on available parameters. This method should be the only one you should need to look at to understand how the Android SDK is chosen, and from where on disk.
org.apache.maven.plugin.MojoExecutionException
- if no Android SDK path configuration is available at all.protected Jack getJack()
protected final File getUnpackedLibsDirectory()
public final File getUnpackedLibFolder(org.apache.maven.artifact.Artifact artifact)
protected final File getUnpackedAarClassesJar(org.apache.maven.artifact.Artifact artifact)
protected final File getUnpackedApkLibSourceFolder(org.apache.maven.artifact.Artifact artifact)
protected final File getUnpackedLibResourceFolder(org.apache.maven.artifact.Artifact artifact)
protected final File getUnpackedLibAssetsFolder(org.apache.maven.artifact.Artifact artifact)
public final File getUnpackedLibNativesFolder(org.apache.maven.artifact.Artifact artifact)
artifact
- Android dependency that is being referenced.public static File getLibraryUnpackDirectory(File unpackedApkLibsDirectory, org.apache.maven.artifact.Artifact artifact)
protected AndroidNdk getAndroidNdk() throws org.apache.maven.plugin.MojoExecutionException
Returns the Android NDK to use.
Current implementation looks for <ndk><path>
configuration in pom, then System
property android.ndk.path
, then environment variable ANDROID_NDK_HOME
.
This is where we collect all logic for how to lookup where it is, and which one to choose. The lookup is based on available parameters. This method should be the only one you should need to look at to understand how the Android NDK is chosen, and from where on disk.
org.apache.maven.plugin.MojoExecutionException
- if no Android NDK path configuration is available at all.public File[] getResourceOverlayDirectories()
protected final boolean isAPKBuild()
protected final void copyFolder(File sourceFolder, File targetFolder) throws org.apache.maven.plugin.MojoExecutionException
The the target folder doesn't exist it will be created.
sourceFolder
- Folder from which to copy the resources.targetFolder
- Folder to which to copy the files.org.apache.maven.plugin.MojoExecutionException
- if the files cannot be copied.protected final UnpackedLibHelper getUnpackedLibHelper()
protected final ArtifactResolverHelper getArtifactResolverHelper()
protected final NativeHelper getNativeHelper()
Copyright © 2008–2019 simpligility technologies inc.. All rights reserved.