Details
-
Bug
-
Resolution: Unresolved
-
P3: Somewhat important
-
None
-
Qt Creator 11.0.3
Description
My goal is to build an Android application with QtCreator by using cmake as the build system. I use the following basic settings:
- Android ABI level 30
- iconv to convert between character sets
Here a small code excerpt which does not compile with an Android ABI level less then 29:
#include <iconv.h> /** * @brief EncodeTo convert into another character set. * * This method takes a string and converts it into another character set. * * @param buf A pointer to a buffer large enough to hold the result. * @param len The length of the buffer \p buf. * @param str A pointer to a string. The content will be converted. * @param from The name of the character set in \p str. * @param to The name of the target charcter set. * @return The pointer \p buf. This buffer is filled up to the length of \p str * or the zero byte. Whichever comes first. */ char *EncodeTo(char* buf, size_t *len, const string& str, const string& from, const string& to) { if (!buf || str.empty()) return 0; iconv_t cd = iconv_open(from.c_str(), to.c_str()); if (cd == (iconv_t) -1) return nullptr; char *in_buf = (char *)str.c_str(); size_t in_left = str.length() - 1; char *out_buf = buf; size_t out_left = *len - 1; do { if (iconv(cd, &in_buf, &in_left, &out_buf, &out_left) == (size_t) -1) return nullptr; } while (in_left > 0 && out_left > 0); *out_buf = 0; iconv_close(cd); *len = out_buf - buf; return buf; }
In the build settings of QtCreator, at the section cmake, I set the ANDROID_PLATFORM to android-30. I set the same to ANDROID_NDK_PLATFORM. Then I set the QT_ANDROID_BUILD_ALL_ABIS to ON.
In the section Create Android-APK I set Android build platform-SDK also to android-30.
Also in the section Build environment I set ANDROID_NDK_PLATFORM to android-30.
Then, after cmake was running again and created the build files, I start the compilation of the C++ code. You can take any C++ example for Android to try this as long as it contains some code only available at a level higher then 27.
The main architecture, which is x86_64 in my case, build quite fine, but the other architectures not. The reason for this is that only for the main architecture android-30 is set and all others use the minimal ABI level 23.
After a closer look to the cmake macros I found out that the ANDROID_PLATFORM is not set for the architectures. I found a solution for this:
- Go to the directory where Qt is installed (e.g. /opt/Qt/6.5.x)
- With a text editor open the file android_x86_64/lib/cmake/Qt6Core/Qt6AndroidMacros.cmake.
- Search for a function called _qt_internal_configure_android_multiabi_target. You'll find it around line 1180.
Look for this code sequence:
if(DEFINED QT_HOST_PATH_CMAKE_DIR) list(APPEND extra_cmake_args "-DQT_HOST_PATH_CMAKE_DIR=${QT_HOST_PATH_CMAKE_DIR}") endif() if(CMAKE_MAKE_PROGRAM) list(APPEND extra_cmake_args "-DCMAKE_MAKE_PROGRAM=${CMAKE_MAKE_PROGRAM}") endif()
Add the following lines:
if(ANDROID_PLATFORM) list(APPEND extra_cmake_args "-DANDROID_PLATFORM=${ANDROID_PLATFORM}") endif()
Then compile again. Now it should work.
This error exists at least from version 6.5.0 on. It is also present in Qt 6.5.3.
A.T.