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 5.10.1 try to compile a basic app for Android arm using cmake
Forum Updated to NodeBB v4.3 + New Features

Qt 5.10.1 try to compile a basic app for Android arm using cmake

Scheduled Pinned Locked Moved Solved Mobile and Embedded
7 Posts 3 Posters 2.7k Views 1 Watching
  • 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.
  • S Offline
    S Offline
    Soda31
    wrote on last edited by Soda31
    #1

    Hello everybody !

    Well I'm near to begin crazy :

    I try to compile a hello world app using Qt 5.10.1, cmake for Android

    I installed all necessary things (sdk, ndk, ...) and I have no problem to compile and install a basic project using pro file on my smartphone

    With my CMakeLists.txt I'm not able to generate files to compile
    I have strange errors and when I think to solve them other bad things appear
    The same project compiles and runs fine using msvc !

    Well someone knows where I could download a working sample of a qt app using cmake for Android or have explanations to special things to do ?

    Here is the content of my cmakelist file

    cmake_minimum_required(VERSION 2.8.11)

    project(testproject)

    #Find includes in corresponding build directories
    set(CMAKE_INCLUDE_CURRENT_DIR ON)
    #Instruct CMake to run moc automatically when needed.
    set(CMAKE_AUTOMOC ON)

    #Find the QtWidgets library
    find_package(Qt5Widgets)

    set(SOURCES
    src/main.cpp
    src/mainwindow.cpp
    )

    set(FORMS
    forms/mainwindow.ui
    )
    qt5_wrap_ui(FORM_H ${FORMS})

    #Tell CMake to create the helloworld executable
    add_executable(helloworld ${SOURCES} ${FORM_H})

    #Use the Widgets module from Qt 5.
    target_link_libraries(helloworld Qt5::Widgets)

    I tryed to add following things

    set(CMAKE_TOOLCHAIN_FILE "xxxxxxxxxxx/AppData/Local/Android/Sdk/ndk-bundle/build/cmake/android.toolchain.cmake")
    set(CMAKE_PREFIX_PATH "C:/Qt/opensource/5.10.x/5.10.1/5.10.1/android_armv7/bin")

    set(Qt5Widgets_DIR "C:/Qt/opensource/5.10.x/5.10.1/5.10.1/android_armv7/lib/cmake/Qt5Widgets")
    set(Qt5Gui_DIR "C:/Qt/opensource/5.10.x/5.10.1/5.10.1/android_armv7/lib/cmake/Qt5Gui")
    set(Qt5Core_DIR "C:/Qt/opensource/5.10.x/5.10.1/5.10.1/android_armv7/lib/cmake/Qt5Core")

    Thanks !

    S 1 Reply Last reply
    0
    • S Soda31

      Hello everybody !

      Well I'm near to begin crazy :

      I try to compile a hello world app using Qt 5.10.1, cmake for Android

      I installed all necessary things (sdk, ndk, ...) and I have no problem to compile and install a basic project using pro file on my smartphone

      With my CMakeLists.txt I'm not able to generate files to compile
      I have strange errors and when I think to solve them other bad things appear
      The same project compiles and runs fine using msvc !

      Well someone knows where I could download a working sample of a qt app using cmake for Android or have explanations to special things to do ?

      Here is the content of my cmakelist file

      cmake_minimum_required(VERSION 2.8.11)

      project(testproject)

      #Find includes in corresponding build directories
      set(CMAKE_INCLUDE_CURRENT_DIR ON)
      #Instruct CMake to run moc automatically when needed.
      set(CMAKE_AUTOMOC ON)

      #Find the QtWidgets library
      find_package(Qt5Widgets)

      set(SOURCES
      src/main.cpp
      src/mainwindow.cpp
      )

      set(FORMS
      forms/mainwindow.ui
      )
      qt5_wrap_ui(FORM_H ${FORMS})

      #Tell CMake to create the helloworld executable
      add_executable(helloworld ${SOURCES} ${FORM_H})

      #Use the Widgets module from Qt 5.
      target_link_libraries(helloworld Qt5::Widgets)

      I tryed to add following things

      set(CMAKE_TOOLCHAIN_FILE "xxxxxxxxxxx/AppData/Local/Android/Sdk/ndk-bundle/build/cmake/android.toolchain.cmake")
      set(CMAKE_PREFIX_PATH "C:/Qt/opensource/5.10.x/5.10.1/5.10.1/android_armv7/bin")

      set(Qt5Widgets_DIR "C:/Qt/opensource/5.10.x/5.10.1/5.10.1/android_armv7/lib/cmake/Qt5Widgets")
      set(Qt5Gui_DIR "C:/Qt/opensource/5.10.x/5.10.1/5.10.1/android_armv7/lib/cmake/Qt5Gui")
      set(Qt5Core_DIR "C:/Qt/opensource/5.10.x/5.10.1/5.10.1/android_armv7/lib/cmake/Qt5Core")

      Thanks !

      S Offline
      S Offline
      Soda31
      wrote on last edited by Soda31
      #2

      Well after some long hours I abandoned Qt Creator and I used Android Studio to use cmake and generate apk

      Build is now fine but I have a new question:

      My Qt app has a main and I understand that to launch my app with Android I need to generate a lib

      I do not find enough informations to convert or adapt my initial app

      #include "mainwindow.h"
      #include <QApplication>
      #include <QDebug>

      int main(int argc, char *argv[])
      {
      QApplication a(argc, argv);

      qDebug() << "TEST";
      

      MainWindow w;
      w.show();

      return a.exec();
      

      }

      With pro files from Qr Creator compiling to Android is really easy (nothing to do in source code)

      Well suggestions or ideas of what I should work to migrate my app to be usable with Android studio and cmake ?

      Thanks !

      1 Reply Last reply
      0
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #3

        Hi,

        I haven't done any test with it but it looks like this Qt-Android-CMake project might be what you are looking for.

        Hope it helps

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        S 1 Reply Last reply
        0
        • SGaistS SGaist

          Hi,

          I haven't done any test with it but it looks like this Qt-Android-CMake project might be what you are looking for.

          Hope it helps

          S Offline
          S Offline
          Soda31
          wrote on last edited by
          #4

          Hello SGaist,

          Thanks for your suggestion
          I'll try it this week

          I'm also going to try to create a Qt lib and call a function from java code like it is showed in some example

          But I don't know if it will work using QMainWindow !

          S 1 Reply Last reply
          1
          • S Soda31

            Hello SGaist,

            Thanks for your suggestion
            I'll try it this week

            I'm also going to try to create a Qt lib and call a function from java code like it is showed in some example

            But I don't know if it will work using QMainWindow !

            S Offline
            S Offline
            Soda31
            wrote on last edited by
            #5

            Hello SGaist,

            Well I tryed to use Qt-Android-CMake project to generate apk with qt libs using cmake

            There are things that did not worked quickly (for example I used ndk toolchain instead included toolchain)

            But after few hours of debug and tests I was able to genetate my first apk and installed it successfully on my smartphone !

            QtCreator and pro files are fine to generate apk too but finally lots of things are hidden and hard to solve when a problem occurs (I'm not able to generate apk with QtCreator and cmake)

            So, I'm really happy now !

            Thanks for the tip

            A 1 Reply Last reply
            1
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              You're welcome !

              Since you have it working now, please mark the thread as solved using the "Topic Tools" button so that other forum users may know a solution has been found :)

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              0
              • S Soda31

                Hello SGaist,

                Well I tryed to use Qt-Android-CMake project to generate apk with qt libs using cmake

                There are things that did not worked quickly (for example I used ndk toolchain instead included toolchain)

                But after few hours of debug and tests I was able to genetate my first apk and installed it successfully on my smartphone !

                QtCreator and pro files are fine to generate apk too but finally lots of things are hidden and hard to solve when a problem occurs (I'm not able to generate apk with QtCreator and cmake)

                So, I'm really happy now !

                Thanks for the tip

                A Offline
                A Offline
                alvarobasi
                wrote on last edited by
                #7

                @Soda31 Hi! I'm following "Qt-Android-Cmake"steps copying your CMakeFile.txt for my basic QtCreator Android project. However, when compiling I get an error like this: "Android platform 'android-14' does not exist in SDK". How can I change the target platform?

                Regards,

                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