Qt C++ Android Remote MySQL
-
Hello guys,
I have been developing an Android app for a commercial project using Qt C++ with a QML interface.
I have been trying to get a remote connection to my Maria DB on a dedicated server. However, I'm having issues with the MySQL driver software; it seems that my computer does not have the required libraries. When I deploy for Windows, the MySQL library is available, but not loaded. And when I deploy for Android, it simply isn't there at all.
W libApp_CppQML.so: QSqlDatabase: QMYSQL driver not loaded
W libApp_CppQML.so: QSqlDatabase: available drivers: QSQLITEAlthough I have been following tutorials, I either get errors when I make, or the files do not get generated. I have placed the DLLs in the same place as the project executable with no luck.
https://doc.qt.io/qt-5/sql-driver.html
https://www.youtube.com/watch?v=_u7TcjIDNzw
https://www.youtube.com/watch?v=r1TbNjJSlX8- "libmysql.dll", "qsqlmysqld.dll" and "qsqlmysql.dll" to program executable locations.
- "sql" added to Qt+= pro configuration.
- Gradle is configured for Android.
Qt Creator 4.11.0, based on Qt 5.14.0 (MSVC 2017 32 bit, from rev 017ed74400) on Windows 10 64-bit, deploying to a Note 7P on Android version 9, compiling with Android for arm64-v8a (Clang Qt 5.12.5 for Android ARM64-v8a).
Different people are saying to download different versions of the C connectors and SQL servers; do I download 64-bit, or do I need 32-bit for Android devices? Are there any more up-to-date tutorials or pre-compiled versions of Qt?
I have uninstalled all versions of MySQL and connector software, as I had around 10 different versions from trying to get this to work!
Any help would be appreciated.
Thanks,
Ryan -
@Ryan-R said in Qt C++ Android Remote MySQL:
"libmysql.dll", "qsqlmysqld.dll" and "qsqlmysql.dll" to program executable locations.
Why? Please read the documentation: https://doc.qt.io/qt-5/deployment-plugins.html and https://doc.qt.io/qt-5/sql-driver.html#how-to-build-the-qmysql-plugin-on-windows
-
Hello,
Thanks for the reply! I have followed the tutorial you posted for building the SQL Drivers; I have installed mysql-installer-web-community-8.0.18.0.msi; custom install. However, there is only the option for C++, not C as stated in the tutorial. So I went ahead and installed the C++ version just in case, browsed to "C:\Program Files (x86)\MySQL\Connector C++ 8.0" and the DLLs (libmysql.lib, libmysql.dll & mysql.h) are not present.
I'm not sure if I'm missing something obvious!
Thanks,
Ryan -
@Ryan-R said in Qt C++ Android Remote MySQL:
libmysql.lib, libmysql.dll & mysql.h
Those should be in lib and include subdirectories.
-
Thanks for the reply! They're not in the sub-directories either.
I still find it strange that the tutorial is asking for a C connector, but the only download they provide is for C++ (even though my app is coded in C++/QML).
-
Ok, so I've got it installed; all of the files are present. Now when I try to run qmake with the following command:
C:\Qt\5.12.5\src\qtbase\src\plugins\sqldrivers> C:\Qt\5.12.5\android_arm64_v8a\bin\qmake -- MYSQL_INCDIR="C:/Program Files (x86)/MySQL/MySQLConnector C 6.1/include" MYSQL_LIBDIR="C:/Program Files/MySQL/MySQL Connector C 6.1/lib"
I get the following error message:
C:\Qt\5.12.5\src\qtbase\src\plugins\sqldrivers> C:\Qt\5.12.5\android_arm64_v8a\bin\qmake Project ERROR: You need to set the ANDROID_NDK_ROOT environment variable to point to your Android NDK. Could not read qmake configuration file C:/Qt/5.12.5/android_arm64_v8a/mkspecs/android-clang/qmake.conf. Error processing project file: C:\Qt\5.12.5\src\qtbase\src\plugins\sqldrivers\sqldrivers.pro
I edit the file qmake.conf. However, I can't seem to find any variables named "ANDROID_NDK_ROOT". Do I need to add this as a new line to the configuration file?
# qmake configuration for building with android-clang MAKEFILE_GENERATOR = UNIX QMAKE_PLATFORM = android QMAKE_COMPILER = gcc clang llvm CONFIG += android_install unversioned_soname unversioned_libname plugin_with_soname android_deployment_settings include(../common/linux.conf) include(../common/gcc-base-unix.conf) include(../common/clang.conf) include(../common/android-base-head.conf) NDK_LLVM_PATH = $$NDK_ROOT/toolchains/llvm/prebuilt/$$NDK_HOST QMAKE_CC = $$NDK_LLVM_PATH/bin/clang QMAKE_CXX = $$NDK_LLVM_PATH/bin/clang++ equals(ANDROID_TARGET_ARCH, armeabi-v7a): \ QMAKE_CFLAGS += -target armv7-none-linux-androideabi else: equals(ANDROID_TARGET_ARCH, armeabi): \ QMAKE_CFLAGS += -target armv5te-none-linux-androideabi else: equals(ANDROID_TARGET_ARCH, arm64-v8a): \ QMAKE_CFLAGS += -target aarch64-none-linux-android else: equals(ANDROID_TARGET_ARCH, x86): \ QMAKE_CFLAGS += -target i686-none-linux-android -mstackrealign else: equals(ANDROID_TARGET_ARCH, x86_64): \ QMAKE_CFLAGS += -target x86_64-none-linux-android else: equals(ANDROID_TARGET_ARCH, mips): \ QMAKE_CFLAGS += -target mipsel-none-linux-android else: equals(ANDROID_TARGET_ARCH, mips64): \ QMAKE_CFLAGS += -target mips64el-none-linux-android QMAKE_CFLAGS += -gcc-toolchain $$NDK_TOOLCHAIN_PATH -fno-limit-debug-info QMAKE_LINK = $$QMAKE_CXX $$QMAKE_CFLAGS -Wl,--exclude-libs,libgcc.a -Wl,--exclude-libs,libatomic.a -nostdlib++ equals(ANDROID_TARGET_ARCH, armeabi-v7a): QMAKE_LINK += -Wl,--exclude-libs,libunwind.a QMAKE_CFLAGS += -DANDROID_HAS_WSTRING --sysroot=$$NDK_ROOT/sysroot \ -isystem $$NDK_ROOT/sysroot/usr/include/$$NDK_TOOLS_PREFIX \ -isystem $$NDK_ROOT/sources/cxx-stl/llvm-libc++/include \ -isystem $$NDK_ROOT/sources/android/support/include \ -isystem $$NDK_ROOT/sources/cxx-stl/llvm-libc++abi/include ANDROID_SOURCES_CXX_STL_LIBDIR = $$NDK_ROOT/sources/cxx-stl/llvm-libc++/libs/$$ANDROID_TARGET_ARCH ANDROID_STDCPP_PATH = $$ANDROID_SOURCES_CXX_STL_LIBDIR/libc++_shared.so ANDROID_USE_LLVM = true exists($$ANDROID_SOURCES_CXX_STL_LIBDIR/libc++.so): \ ANDROID_CXX_STL_LIBS = -lc++ else: \ ANDROID_CXX_STL_LIBS = $$ANDROID_SOURCES_CXX_STL_LIBDIR/libc++.so.$$replace(ANDROID_PLATFORM, "android-", "") QMAKE_CFLAGS_OPTIMIZE_SIZE = -Oz include(../common/android-base-tail.conf)
I do have qmake configured for the Qt Creator IDE, but I've never had to use the command-line to compile my projects, as it's all done through the IDE. I can confirm both qmake.conf and sqldrivers.pro are both present in their respective locations.
Thanks for the help!
-
@Ryan-R Just now realised that you're building for Android. In that case the MySQL libs you installed will not help as those are for x86_64 Windows not Android. You will need either find precompiled MySQL libs for Android or build them manually.
-
Any chance you know how to manually build them, or know where to download them for this Android version? I have tried building them before, but was swarmed by errors from following the tutorials.
I really don't want to have to use Xamarin for this app! I've been reading that it might be possible to use JavaScript with QML to execute some type of HTTP request that handles the data instead, and then get the server to run the query with localhost using PHP, instead of the app running the query directly.
I made a back-end website to this app coded in HTML/CSS/PHP/JavaScript/MySQL, but I have only used TCP, UDP and SQL for transferring data between servers/clients.
Some people reccommend XmlHttpRequest or Firebase, but have never used these protocols and wouldn't know where to start, or what the security implications are!
Thanks for the help,
Ryan. -
@Ryan-R said in Qt C++ Android Remote MySQL:
Any chance you know how to manually build them, or know where to download them for this Android version?
No, sorry.
"I made a back-end website to this app coded in HTML/CSS/PHP/JavaScript/MySQL" - then why do you need MySQL client stuff on Android? This sounds unusual. A mobile app should not connect directly to an exposed(!) SQL server, but use some API (like REST API) to communicate with the back-end server.
-
Well it's an analytics portal for displaying information such as user accounts, sales, as as well to configure some parts of the app and embedded machines remotely. We have SSL, I thought that as long as the traffic is encrypted, we have brute-force penetration protection and don't use the root login, there shouldn't any security issues as long as it's configured correctly?
I'll have to start looking at APIs such as REST, are there any additional steps to configure these APIs with Qt, or do they work out-of-the-box with QML?
Thanks for the information!
Ryan