Important: Please read the Qt Code of Conduct -

Qt5.2 + Android + MySQL / PostgreSQL

  • I've just installed Qt5.2 for Linux/x86 and Android, and I notice that while the MySQL and PostgreSQL plugins ( and are available by default for the x86 library (./5.2.0/gcc/plugins/sqldrivers/), they're not available for the Android library (5.2.0/android_armv5/plugins/sqldrivers/), where only is available.

    There's no other way to get MySQL and PostreSQL support on Android without recompiling the whole library myself? Are there any plans to include the libraries like in the x86 version in the future?

  • Lifetime Qt Champion


    For that the first thing needed would be android build of the MySQL and PostgreSQL library (arm version)

    I am not aware of android providing them. I might be wrong though and be happy to be proven so.

  • And isn't Qt able to provide a binary? Is that for licensing reasons or something?

    I've finally followed "this tutorial":, and got it building. As I assume being forced to compile these libraries is as much as a pain in the ass for you, random Internet dwellers, as it is for me, I've automated the process:

    A lot of stuff is hardcoded, but it works for me, and it should be pretty easy to modify for your systems and needs.

  • Patched to rename to

  • Lifetime Qt Champion

    I don't know all the details but what comes to my mind is indeed licensing. Also, that would mean building these libraries on all supported platform (not all have e.g. MySQL) and include them in Qt's source code etc. Not practical at all

  • hi Razziel its possible you send to me your
    dont have more in link

  • I'm sorry I couldn't reply your pm. projetoslinux
    Here you go:

  • Updated version for Qt 5.2.1:

  • Hello Guys I've Qt 5.2.1 x86 for Android, I'm using windows 8 64bit. and I don't know what exactly should I do to make my application that uses MySQL works in Android.
    Note: the Application works fine on desktop.
    Please help

  • I guess you should do something similar to what is being done in my scripts, but for Windows instead of Linux. Or maybe someone has the libraries compiled for Android x86 and can upload them?

  • @RazZziel
    In your script you have used mariadb should I do the same or it is good to use the MySQL Connector since I only need to connect to MySQL and in the Tutorial you followed they mentioned mariaDB and MySQL as two option, which as I understand only one of them should be done, Am I right?


  • MariaDB and MySQL are compatible; I used MariaDB because is what was being used on the tutorial I followed (I didn't make it), but I'm using it to connect both to MySQL and MariaDB servers. However indeed you only need one client library, either MySQL or MariaDB.

  • sorry for this RAzZziel, but dont load, stay longer for 2 months, its possible send to me your script


    [quote author="RazZziel" date="1395676332"]Updated version for Qt 5.2.1:[/quote]

  • Thank you very much RazZziel !!!!

  • Hi
    [quote author="RazZziel" date="1400018116"]This one shouldn't expire:
    Nor this one:[/quote]

    this compile Ok but in running mode
    W/Qt ( 6583): kernel/qsqldatabase.cpp:785 (void QSqlDatabasePrivate::init(const QString&)): QSqlDatabase: QMYSQL driver not loaded
    W/Qt ( 6583): kernel/qsqldatabase.cpp:786 (void QSqlDatabasePrivate::init(const QString&)): QSqlDatabase: available drivers: QSQLITE
    D/Qt ( 6583): ../POSlinux/src/hal/maintablehal2.cpp:10396 (int MainTablehal2::ServerConexionM(int)): Conexxion ext Error

    not load
    how i can load this plugin, in linux my program work normally
    but in Android not load after use your EXCELLENT !!!! script

    why i'm doing wrong ?????

  • @RazZziel said:

    This one shouldn't expire:
    Nor this one:

    After moving to the above patch doesn't work fine so I modified the new one a little bit everything went fine but when the patch arrived to Qt mysql pluing it failed because of the following error:

    /home/hpctech-work/.Qt/android-ndk-r10e//toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin/arm-linux-androideabi-g++ -c -Wno-psabi -march=armv7-a -mfloat-abi=softfp -mfpu=vfp -ffunction-sections -funwind-tables -fstack-protector -fno-short-enums -DANDROID -Wa,--noexecstack -fno-builtin-memmove -std=c++11 -O2 -Os -fomit-frame-pointer -fno-strict-aliasing -finline-limit=64 -mthumb -fvisibility=hidden -fvisibility-inlines-hidden -D_REENTRANT -Wall -Wno-psabi -W -fPIC -DQT_NO_CAST_TO_ASCII -DQT_NO_CAST_FROM_ASCII -DQT_NO_DEBUG -DQT_PLUGIN -DQT_SQL_LIB -DQT_CORE_LIB -I. -isystem /home/hpctech-work/.Qt/android-ndk-r10e/platforms/android-9/arch-arm/usr/include/mariadb -I/home/hpctech-work/.Qt/5.5/android_armv7/include -I/home/hpctech-work/.Qt/5.5/android_armv7/include/QtSql -I/home/hpctech-work/.Qt/5.5/android_armv7/include/QtCore -I. -isystem /home/hpctech-work/.Qt/android-ndk-r10e/sources/cxx-stl/gnu-libstdc++/4.8/include -isystem /home/hpctech-work/.Qt/android-ndk-r10e/sources/cxx-stl/gnu-libstdc++/4.8/libs/armeabi-v7a/include -isystem /home/hpctech-work/.Qt/android-ndk-r10e/platforms/android-9/arch-arm/usr/include -I/home/hpctech-work/.Qt/5.5/android_armv7/mkspecs/android-g++ -o main.o main.cpp
    In file included from /home/hpctech-work/.Qt/5.5/android_armv7/include/QtCore/qnamespace.h:37:0,
                     from /home/hpctech-work/.Qt/5.5/android_armv7/include/QtCore/qobjectdefs.h:41,
                     from /home/hpctech-work/.Qt/5.5/android_armv7/include/QtCore/qobject.h:40,
                     from /home/hpctech-work/.Qt/5.5/android_armv7/include/QtCore/qplugin.h:37,
                     from /home/hpctech-work/.Qt/5.5/android_armv7/include/QtSql/qsqldriverplugin.h:37,
                     from main.cpp:42:
    /home/hpctech-work/.Qt/5.5/android_armv7/include/QtCore/qglobal.h:693:47: error: expected constructor, destructor, or type conversion before 'static_assert'
     #define Q_STATIC_ASSERT_X(Condition, Message) static_assert(bool(Condition), Message)
    /home/hpctech-work/.Qt/5.5/android_armv7/include/QtCore/qplugin.h:136:5: note: in expansion of macro 'Q_STATIC_ASSERT_X'
         Q_STATIC_ASSERT_X(false, "Old plugin system used")
    main.cpp:80:1: note: in expansion of macro 'Q_EXPORT_PLUGIN2'
     Q_EXPORT_PLUGIN2(qsqlmysql, QMYSQLDriverPlugin)
    make: *** [main.o] Error 1
    diff: ./rootfs_files_before.txt: No such file or directory
    hpctech-work@hpctech-work ~/HPCTECH/Projects/MysqlClient/build-libmysql-android $

    How can I fix this issue?

    The full modified patch file is:

    # Based on
    export ANDROID_NDK_ROOT="$HOME/.Qt/android-ndk-r10e/"
    export QT_ROOT="$HOME/.Qt/5.5/"
    here="$(dirname "$0")"
    find "$SR" > "$here/rootfs_files_before.txt" || exit 1
    checkChanges() {
            find "$SR" > "$here/rootfs_files_after.txt" || exit 1
            echo "Changes:"
            diff -u "$here/rootfs_files_before.txt" "$here/rootfs_files_after.txt"
    trap checkChanges EXIT
    # OpenSSL
    dir=$(basename $pkg .tar.gz)
    if [ ! -d $dir ]; then
            wget -c$pkg
            tar -xf $pkg || exit 1
    pushd $dir
            RANLIB="$BR"ranlib CC="$BR"gcc ./Configure android-armv7 --prefix=$SR/usr
            ANDROID_DEV=$SR/usr make #|| exit 1
            ANDROID_DEV=$SR/usr make || exit 1
            make install_sw || exit 1
    # libiconv
    dir=$(basename $pkg .tar.gz)
    if [ ! -d $dir ]; then
            wget -c$pkg
            tar -xf $pkg || exit 1
    pushd $dir
            STRIP="$BR"strip RANLIB="$BR"ranlib OBJDUMP="$BR"objdump AR="$BR"ar CC="$BR"gcc CFLAGS=--sysroot=$SR CPP="$BR"cpp CPPFLAGS=$CFLAGS ./configure --host=arm --prefix=$SR/usr --with-sysroot=$SR
            make || exit 1
            make install || exit 1
    # mariadbclient
    # FIXME: This one fails to build, linker errors
    dir=$(basename $pkg .tar.gz)
    if [ ! -d $dir ]; then
            wget -c $url
            tar -xf $pkg || exit 1
    pushd $dir
            sed -i -e "s|ADD_SUBDIRECTORY(unittest/libmariadb)|#ADD_SUBDIRECTORY(unittest/libmariadb)|" CMakeLists.txt
            sed -i -e "N; s|typedef unsigned short ushort;\n#endif|#endif\ntypedef unsigned short ushort;|" include/my_global.h
            sed -i -e "N; s|SET_TARGET_PROPERTIES(libmariadb PROPERTIES VERSION.*||" libmariadb/CMakeLists.txt
            sed -i -e "N; s|SOVERSION \${CPACK_PACKAGE_VERSION_MAJOR})||" libmariadb/CMakeLists.txt # Pig disgusting: the previous multiline thingie should've done it
            sed -i -e "N; s|\${CPACK_PACKAGE_VERSION_MAJOR}||" libmariadb/CMakeLists.txt # Pig disgusting: what the fuck
            mkdir build
            pushd build
            PKG_CONFIG_PATH=$SR/usr/lib/pkgconfig cmake \
    		-DCMAKE_BUILD_TYPE=Release \
    		-DCMAKE_C_FLAGS=--sysroot="$SR" \
    		-DCMAKE_C_COMPILER="$BR"gcc \
    		-DCMAKE_LINKER="$BR"ld \
    		-DCMAKE_AR="$BR"ar \
    		-DCMAKE_NM="$BR"nm \
    		-DCMAKE_OBJCOPY="$BR"objcopy \
    		-DCMAKE_OBJDUMP="$BR"objdump \
    		-DCMAKE_RANLIB="$BR"ranlib \
    		-DCMAKE_STRIP="$BR"strip \
    		-DICONV_INCLUDE_DIR="$SR/usr/include" \
    		-DICONV_LIBRARIES="$SR/usr/lib/libiconv.a" \
    		-DZLIB_INCLUDE_DIR="$SR/usr/include" \
    		-DZLIB_LIBRARY="$SR/usr/lib/" ../ || exit 1
            make install || exit 1
            # ???
            cp build/libmariadb/*.{a,so} "$SR/usr/lib/mariadb/" || exit 1
    # qt
    [ ! -f "$qmake" ] && { echo "Could not find qmake in '$qmake'"; exit 1; }
    [ ! -x "$qmake" ] && { echo "Qmake is not executable in '$qmake'"; exit 1; }
    qtVersion=$(qmake -query QT_VERSION)
    dir=$(basename $pkg .tar.gz)
    if [ ! -d $dir ]; then
    #        wget -c${qtVersion%.*}/$qtVersion/submodules/$pkg
            wget -c${qtVersion%.*}/$qtVersion/$pkg
            tar -xf $pkg || exit 1
    pushd $dir/src/plugins/sqldrivers/mysql/
            $qmake "INCLUDEPATH+=$SR/usr/include/mariadb" "LIBS+=$SR/usr/lib/mariadb/libmariadbclient.a $SR/usr/lib/libssl.a $SR/usr/lib/libcrypto.a $SR/usr/lib/libiconv.a" "LIBPATH+=$SR/usr/lib/mariadb" -o Makefile
            make || exit 1
            make install || exit 1
    echo "BOOYAH!!!"

  • I fixed this issue by using the following modifications

  • Hi,

    Many thanks for "" !
    But i have a problem.
    When :

    PKG_CONFIG_PATH=$SR/usr/lib/pkgconfig cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_C_FLAGS=--sysroot="$SR" -DCMAKE_INS
    R/usr/include" -DZLIB_LIBRARY="$SR/usr/lib/" ../

    I have this error :

    CMake Error at CMakeLists.txt:5 (PROJECT):
      CMAKE_SYSTEM_NAME is 'Android' but 'NVIDIA Nsight Tegra Visual Studio
      Edition' is not installed.

    Build on Windows 10 x64 for Android.
    MySQL Plugin for Qt 5.7.0.

    Many thanks for help.

  • @Yohan07 Do you success on building mysql driver for android on windows?
    I want to build it also by qt5.11.0 ,but can't get it?

Log in to reply