AndroidToolchain¶
Enable easy compilation of cmake projects on Android.
By using this android toolchain, the projects will be set up to compile the specified project targeting an Android platform, depending on its input. Furthermore, if desired, an APK can be directly generated by using the androiddeployqt tool.
Note
This module requires CMake 3.1.
Since 1.7.0.
Usage¶
To use this file, you need to set the CMAKE_TOOLCHAIN_FILE to point to
AndroidToolchain.cmake on the command line:
cmake -DCMAKE_TOOLCHAIN_FILE=/usr/share/ECM/toolchain/AndroidToolchain.cmake
You will also need to provide the locations of the Android NDK and SDK. This can be done on the commandline or with environment variables; in either case the variable names are:
ANDROID_NDK- The NSK root path.
ANDROID_SDK_ROOT- The SSK root path.
Additional options are specified as cache variables (eg: on the command line):
ANDROID_ARCHITECTURE- The architecture to compile for. Default:
arm. ANDROID_TOOLCHAIN- The toolchain to use. See the
toolchainsdirectory of the NDK. Default:arm-linux-androideabi. ANDROID_ABI- The ABI to use. See the
sources/cxx-stl/gnu-libstdc++/*/libsdirectories in the NDK. Default:armeabi-v7a. ANDROID_GCC_VERSION- The GCC version to use. Default:
4.9. ANDROID_API_LEVEL- The API level
to require. Default:
14. ANDROID_SDK_BUILD_TOOLS_REVISION- The build tools version to use. Default:
21.1.1.
Deploying Qt Applications¶
After building the application, you will need to generate an APK that can be
deployed to an Android device. This module integrates androiddeployqt support
to help with this for Qt-based projects. To enable this, set the
QTANDROID_EXPORTED_TARGET variable to the target you wish to export as an
APK, as well as ANDROID_APK_DIR to a directory containing some basic
information. This will create a create-apk-<target> target that will
generate the APK file. See the Qt on Android deployment documentation for more information.
For example, you could do:
cmake \
-DCMAKE_TOOLCHAIN_FILE=/usr/share/ECM/toolchain/AndroidToolchain.cmake \
-DQTANDROID_EXPORTED_TARGET=myapp \
-DANDROID_APK_DIR=myapp-apk
make
make create-apk-myapp
The APK would then be found in myapp_build_apk/bin in the build directory.