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. Building android Project without Qt Creator Qt6
Forum Updated to NodeBB v4.3 + New Features

Building android Project without Qt Creator Qt6

Scheduled Pinned Locked Moved Unsolved Mobile and Embedded
5 Posts 3 Posters 1.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.
  • A Offline
    A Offline
    Aninoss
    wrote on 2 Dec 2022, 14:42 last edited by Aninoss 12 Feb 2022, 14:55
    #1

    Can I build an Android project with Cmake and Qt Quick from Command lines only🤔?
    because in the past few days I was stuck trying to build an Android Application using Visual studio code, Cmake, and Qt Quick because it's kind of faster and gives me more freedom to a deeper understanding of how things work :).
    but I can't find any helpful information on the web on how to build without Qt Creator 🧐

    T 1 Reply Last reply 2 Dec 2022, 17:44
    0
    • J Offline
      J Offline
      JoeCFD
      wrote on 2 Dec 2022, 15:11 last edited by
      #2

      https://github.com/LaurentGomila/qt-android-cmake

      1 Reply Last reply
      1
      • A Aninoss
        2 Dec 2022, 14:42

        Can I build an Android project with Cmake and Qt Quick from Command lines only🤔?
        because in the past few days I was stuck trying to build an Android Application using Visual studio code, Cmake, and Qt Quick because it's kind of faster and gives me more freedom to a deeper understanding of how things work :).
        but I can't find any helpful information on the web on how to build without Qt Creator 🧐

        T Offline
        T Offline
        TomZ
        wrote on 2 Dec 2022, 17:44 last edited by
        #3

        @Aninoss said in Building android Project without Qt Creator Qt6:

        but I can't find any helpful information on the web on how to build without Qt Creator

        Ha, sounds familiar. Yeah, docs suck nowadays on Qt.

        My personal requirement was to not have to have Java or the SDK installed on my machine. Instead I wanted to use Docker for the toolchain.

        So, it works for me. Kinda. I now use CMake and make only, can be done from the commandline and thus, i'm sure, from other IDEs as well.

        The main trick, that Qt docs NEVER say, is that the standard way of doing things in CMake is not compatible. Non-simple projects simply can not work without some hacks.
        First rule: You are not allowed to use add_executable() and friends.
        Instead you have to use qt6_add_executable().

        Unfortunately, as a friendly gesture, that method calls target_link_libraries with qt-core. Which basically screws you over as you are not allowed to call that line twice and nobody links only to QtCore.
        For this I patched Qt. here.

        The relevant cmake example that now works: here.

        1 Reply Last reply
        1
        • A Offline
          A Offline
          Aninoss
          wrote on 2 Dec 2022, 21:11 last edited by
          #4

          The Compiler Output after debugging

          cmake -G"MinGW Makefiles"
                -DCMAKE_TOOLCHAIN_FILE="%ANDROID_NDK%/build/cmake/android.toolchain.cmake" 
                -DCMAKE_MAKE_PROGRAM="%ANDROID_NDK%/prebuilt/windows-x86_64/bin/make.exe" 
          

          Compiler Output

          -- ANDROID_PLATFORM not set. Defaulting to minimum supported version 16.
          -- Android: Targeting API '16' with architecture 'arm', ABI 'armeabi-v7a', and processor 'armv7-a'
          -- Android: Selected unified Clang toolchain
          -- The C compiler identification is Clang 12.0.8
          -- The CXX compiler identification is Clang 12.0.8
          -- Detecting C compiler ABI info
          -- Detecting C compiler ABI info - done
          -- Check for working C compiler: C:/Users/Aninoss/AppData/Local/Android/Sdk/ndk/23.1.7779620/toolchains/llvm/prebuilt/windows-x86_64/bin/clang.exe - skipped
          -- Detecting C compile features
          -- Detecting C compile features - done
          -- Detecting CXX compiler ABI info
          -- Detecting CXX compiler ABI info - done
          -- Check for working CXX compiler: C:/Users/Aninoss/AppData/Local/Android/Sdk/ndk/23.1.7779620/toolchains/llvm/prebuilt/windows-x86_64/bin/clang++.exe - skipped
          -- Detecting CXX compile features
          -- Detecting CXX compile features - done
          CMake Error at CMakeLists.txt:27 (find_package):
            By not providing "FindQt6.cmake" in CMAKE_MODULE_PATH this project has
            asked CMake to find a package configuration file provided by "Qt6", but
            CMake did not find one.
          
            Could not find a package configuration file provided by "Qt6" with any of
            the following names:
          
              Qt6Config.cmake
              qt6-config.cmake
          
            Add the installation prefix of "Qt6" to CMAKE_PREFIX_PATH or set "Qt6_DIR"
            to a directory containing one of the above files.  If "Qt6" provides a
            separate development package or SDK, be sure it has been installed.
          
          
          -- Configuring incomplete, errors occurred!
          See also "C:/Users/Aninoss/Documents/Programming/Qt/AndroidCmakeTest/Qml And Js/build/CMakeFiles/CMakeOutput.log".
          

          My CMake file

          cmake_minimum_required(VERSION 3.21)
          project(QHelloWorld VERSION 1.0.0)
          
          # Generate compile_commands.json for use by YCM
          set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
          
          set(CMAKE_AUTOMOC ON)
          set(CXX_STANDARD 17)
          set(CXX_STANDARD_REQUIRED ON)
          
          #======================= INCLUSION OF Qt =======================#
          set(CMAKE_INCLUDE_CURRENT_DIR ON)
          set(SOURCE_DIR "${CMAKE_SOURCE_DIR}/src")
          set(INCLUDE_DIR "${CMAKE_SOURCE_DIR}/include")
          set(UI_DIR "${CMAKE_SOURCE_DIR}/ui")
          
          
          include_directories(${SOURCE_DIR})
          include_directories(${INCLUDE_DIR})
          include_directories(${UI_DIR})
          
          file(GLOB_RECURSE SOURCES
              "${SOURCE_DIR}/*.cpp"
              "${INCLUDE_DIR}/*.h"
          )
          
          find_package(Qt6 COMPONENTS Gui Quick Core REQUIRED)
          
          if(ANDROID)
              add_library(QHelloWorld SHARED ${SOURCES})
              include(qt-android-cmake/AddQtAndroidApk.cmake)
              add_qt_android_apk(my_app_apk QHelloWorld)
          eles()
              qt_add_executable(QHelloWorld ${SOURCES})
          endif()
          
          qt_add_qml_module(QHelloWorld
              URI rec
              VERSION 1.0.0
              QML_FILES
                  ui/main.qml
                  ui/constants.js
                  ui/javascriptFile.js
          )
          
          target_link_directories(QHelloWorld PUBLIC ${SOURCE_DIR})
          target_link_directories(QHelloWorld PUBLIC ${INCLUDE_DIR})
          target_link_directories(QHelloWorld PUBLIC ${UI_DR})
          
          target_link_libraries(QHelloWorld PRIVATE Qt6::Gui Qt6::Quick Qt6::Core)
          

          Any help :/

          1 Reply Last reply
          0
          • T Offline
            T Offline
            TomZ
            wrote on 2 Dec 2022, 21:26 last edited by
            #5

            I use these 3 cmake arguments;

                -DCMAKE_TOOLCHAIN_FILE=/opt/android-qt6/lib/cmake/Qt6/qt.toolchain.cmake \
                -DANDROID_SDK_ROOT=/opt/android-sdk \
                -DANDROID_NDK_ROOT=/opt/android-ndk \
            
            1 Reply Last reply
            0

            1/5

            2 Dec 2022, 14:42

            • Login

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