Qt 5.10.1 try to compile a basic app for Android arm using cmake
-
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 !
-
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 !
-
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
-
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
-
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 :)
-
@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,