ECMAddAndroidApk — Extra CMake Modules 6.29.0 documentation

# ECMAddAndroidApk

Functions for creating Android APK packages using Qt6’s `androiddeployqt` tool as well as the associated Fastlane metadata.

    ecm_add_android_apk(<target>
        [ANDROID_DIR <dir>]
        [PACKAGE_NAME <name>]
        # TODO extra args?
    )

Creates an Android APK for the given target.

If `ANDROID_DIR` is given, the Android manifest file as well as any potential Gradle build system files or Java/Kotlin source files are taken from that directory. If not set, the standard template shipped with Qt6 is used, which in usually not what you want for production applications.

If `PACKAGE_NAME` is given, it is used as name for the Android APK. If not set, the `target` name is used. Since 6.10.0

The use of this function creates a build target called `create-apk-<target>` which will run `androiddeployqt` to produce an (unsigned) APK, as well as convert Appstream application metadata (if present) into the Fastlane format used by F-Droid and Play store automation.

There’s also a `create-apk` convenience target being created that will build all APKs defined in a project.

When building for another platform than Android, this function does nothing.

The following variables impact the behavior: `ECM_ADDITIONAL_FIND_ROOT_PATH`

> See documentation in the Android toolchain file.

`ECM_APK_STAGING_ROOT_PATH`

  For use with Craft’s image directory. If set this is used as the source for all content of the APK rather than the search paths used for building. This allows to separate e.g. development files from what ends up in the APK.

Since 6.0.0

For automatically deriving APK versions from CMake this creates a `ecm-version.gradle` file which defines the following variables: `ecmVersionName`: Set to `PROJECT_VERSION` `ecmVersionCode`: Derived from the current time in local builds, and from `CI_PIPELINE_CREATED_AT`

> in builds from Gitlab pipelines. This ensures a strictly increasing version code as well as synchronized version codes for APKs of multiple architectures when build in a Gitlab pipeline.

This can be included by calling `apply from: '../ecm-version.gradle'` in the project’s `build.gradle` file and is typically used in manifest placeholders:

``` defaultConfig {

> versionName ecmVersionName versionCode ecmVersionCode manifestPlaceholders = [versionName: ecmVersionName, versionCode: ecmVersionCode] …

## }

Since 6.12.0