IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)

Qt for Android - Building User Projects

How to build user projects using Qt for Android.

Article lu   fois.

L'auteur

Liens sociaux

Viadeo Twitter Facebook Share on Google+   

Building with CMake

To build CMake projects with an installed or a self-built Qt, use qt-cmake wrapper. For Android the following has to be provided:

 
Sélectionnez
<qt_for_android_install_path>/bin/qt-cmake \
    -DANDROID_SDK_ROOT=<android_sdk_path> \
    -DANDROID_NDK_ROOT=<android_ndk_path> \
    -S <source_dir> -B <build_dir> \
    [-G"<Ninja|Unix Makefiles>"]

Qt for Android automatically collects Android package dependencies from a project build tree and uses known library paths. It's also possible to specify various dependencies that need to be deployed within a target package using the following target properties:

Building multi-ABI packages using CMake

Introduced in Qt 6.3.

There are several ways to enable building a multi-ABI package. By default only the single ABI belonging to the qt-cmake script is selected. Setting the QT_ANDROID_BUILD_ALL_ABIS variable to TRUE enables the automatic detection of available Qt for Android SDKs. The detection mechanism assumes the use of the default directory structure supplied by the Qt installer:

 
Sélectionnez
<path/to/Qt>/\1
    android_armv7
    android_arm64_v8a
    android_x86
    android_x86_64

The command below shows the easiest way to build an Android multi-ABI package using the Qt for Android SDKs supplied by the Qt installer:

 
Sélectionnez
<qt_for_android_install_path>/bin/qt-cmake \
    -DQT_ANDROID_BUILD_ALL_ABIS=TRUE \
    -DANDROID_SDK_ROOT=<android_sdk_path> \
    -DANDROID_NDK_ROOT=<android_ndk_path> \
    -S <source_directory> -B <build_directory>

Using the QT_ANDROID_ABIS variable, it's possible to customize the list of ABIs the project is built for. The corresponding Qt for Android development kits needs to follow the directory structure described previously. The following command line configures a project for arm64-v8a and x86 ABIs only:

 
Sélectionnez
<qt_for_android_install_path>/bin/qt-cmake \
    -DQT_ANDROID_ABIS="arm64-v8a;x86" \
    -DANDROID_SDK_ROOT=<android_sdk_path> \
    -DANDROID_NDK_ROOT=<android_ndk_path> \
    -S <source_directory> -B <build_directory>

The ABI of the primary SDK that qt-cmake script belongs to is added to the list of used ABIs unconditionally. It's not possible to exclude it from the build.

QT_ANDROID_BUILD_ALL_ABIS has higher priority than QT_ANDROID_ABIS.

Paths to the Qt for Android SDKs that do not match the default directory structure can be changed using the corresponding QT_PATH_ANDROID_ABI_<ABI> variables.

The following example enables the automatic detection of available Qt for Android SDKs and specifies custom paths to armeabi-v7a and arm64-v8a SDKs:

 
Sélectionnez
&lt;qt_for_android_install_path&gt;/bin/qt-cmake \
    -DQT_ANDROID_BUILD_ALL_ABIS=TRUE
    -DQT_PATH_ANDROID_ABI_armeabi-v7a="&lt;Qt/for/armeabi-v7a&gt;" \
    -DQT_PATH_ANDROID_ABI_arm64-v8a="&lt;Qt/for/arm64-v8a&gt;" \
    -DANDROID_SDK_ROOT=&lt;android_sdk_path&gt; \
    -DANDROID_NDK_ROOT=&lt;android_ndk_path&gt; \
    -S &lt;source_directory&gt; -B &lt;build_directory&gt;

It's also possible to set the QT_ANDROID_ABIS target property that specifies a list of ABIs that the single executable target is built for. For example:

 
Sélectionnez
\dots 0
qt_add_executable(MyApp main.cpp)

set_target_properties(MyApp PROPERTIES QT_ANDROID_ABIS "arm64-v8a;x86")

The MyApp target will be built for armeabi-v7a and arm64-v8a only, even if the QT_ANDROID_BUILD_ALL_ABIS or QT_ANDROID_ABIS variable is set.

Building with qmake

You can continue to use qmake to build user projects.

Building multi-ABI packages with qmake is not supported in Qt 6.

See Also

Vous avez aimé ce tutoriel ? Alors partagez-le en cliquant sur les boutons suivants : Viadeo Twitter Facebook Share on Google+