Qt Creator cmake project add application icon to Android application
-
I am developing an Android app using a cmake project created with Qt Creator. The application builds and runs fine on the target device (arm64-v8a). However the application uses the android standard application icon.
I tried the following:
I created a AndroidManifest.xml under Projects -> Build -> Build Android APK -> Create Templates. In the AndroidManifest.xml I chose my own icon. The AndroidManifest.xml together withg gradle files is saved in my project folder under android (e.g. android/AndroidManifest.xml). Furthermore I added it to the library in the CMakeLists.txt:set(ANDROID_PACKAGE_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/android) add_library(Test SHARED android/AndroidManifest.xml main.cpp qml.qrc ${TS_FILES} )
However, the application icon does not change when the app is deployed on the phone (still uses the default android icon).
How can I use a custom application icon (e.g. a .png image) using Qt Creator and cmake?
I am using Qt 5.14.0 and Qt Creator 4.11.1.
-
I have similar issue. It seems that contents from
ANDROID_PACKAGE_SOURCE_DIR/res
are not copied, and I need them to copy for splash screen, etc.If I copy them myself with this workaround:
set(ANDROID_BUID_DIR ${CMAKE_CURRENT_BINARY_DIR}/android-build) #... file(INSTALL android/ DESTINATION ${ANDROID_BUID_DIR} FILES_MATCHING PATTERN "*")
res
contents does appear aftercmake
run, but onceandroiddeployqt
runs (after build step), all these files disappear (being deleted?)! -
Hi,
I hope it's ok to still reply even though this topic is already a bit older.
I had the same issue and this post came up while searching.After some more digging, I could solve the problem by setting the QT_ANDROID_PACKAGE_SOURCE_DIR target property to the corresponding path.
In my project, called "qtodo", this looks as follows:set_target_properties(qtodo PROPERTIES QT_ANDROID_PACKAGE_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/android" )
With this setting, androiddeployqt takes care of everything, including copying the files etc.
I tried this with Qt6 (6.1.0).
Just in case, the full CMakeLists.txt file is available at: https://github.com/ruedigergad/qtodo/blob/master/src/CMakeLists.txtAlso, just in case, I found looking at the following files helpful, e.g.,:
- <PATH_TO_QT_SDK>/android_x86_64/lib/cmake/Qt6Core/Qt6AndroidMacros.cmake
- <PATH_TO_QT_SDK>/android_x86_64/lib/cmake/Qt6/QtPlatformAndroid.cmake
I hope this is helpful.
Cheers,
Ruediger
-
@njeisecke Hi, how can we improve the Qt documentation on this topic?
https://doc.qt.io/qt-6/cmake-target-property-qt-android-package-source-dir.html#cmake-target-property-qt-android-package-source-dir
is where that info is located, but I see that there are other questions around this on the forums.
perhaps a "Setting the App icon for your Qt for Android Application" Example could be linked from here https://doc.qt.io/qt-6/android.html ?
would cover a bit of creator usage, CMake, and how deployment for Android works with Qt. -
HI @leinad18 leinard 18, thanks for posting this. Did you manage to get this working in either qt 5 or qt 6?