Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. Qt Creator cmake project add application icon to Android application
QtWS25 Last Chance

Qt Creator cmake project add application icon to Android application

Scheduled Pinned Locked Moved Unsolved Mobile and Embedded
qt creatorandroidcmake
6 Posts 5 Posters 3.0k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    leinad18
    wrote on last edited by leinad18
    #1

    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.

    1 Reply Last reply
    0
    • TalklessT Offline
      TalklessT Offline
      Talkless
      wrote on last edited by
      #2

      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 after cmake run, but once androiddeployqt runs (after build step), all these files disappear (being deleted?)!

      1 Reply Last reply
      0
      • R Offline
        R Offline
        Ruediger
        wrote on last edited by
        #3

        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.txt

        Also, 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

        1 Reply Last reply
        4
        • N Offline
          N Offline
          njeisecke
          wrote on last edited by
          #4

          Thank you Ruediger, you made my day. I've spent hours looking for this, The Qt/Android/cmake documentation is slightly lacking here.

          Nick BennettN 1 Reply Last reply
          0
          • N njeisecke

            Thank you Ruediger, you made my day. I've spent hours looking for this, The Qt/Android/cmake documentation is slightly lacking here.

            Nick BennettN Offline
            Nick BennettN Offline
            Nick Bennett
            wrote on last edited by
            #5

            @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.

            1 Reply Last reply
            0
            • Nick BennettN Offline
              Nick BennettN Offline
              Nick Bennett
              wrote on last edited by
              #6

              HI @leinad18 leinard 18, thanks for posting this. Did you manage to get this working in either qt 5 or qt 6?

              1 Reply Last reply
              0

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved