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 (libqsqlmysql.so and libqsqlpsql.so) 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 libqsqlite.so 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

    Hi,

    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":http://qt-project.org/wiki/Build_Qt5_mysql_plugin_for_Android, 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: http://pastebin.com/i7QU10hq

    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 libmariadb.so.1 to libmariadb.so http://pastebin.com/0saJePF9


  • 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 http://pastebin.com/i7QU10hq
    dont have more in link



  • I'm sorry I couldn't reply your pm. projetoslinux
    Here you go: http://pastebin.com/RTmFL8fZ



  • Updated version for Qt 5.2.1: http://pastebin.com/k1u6gNe2



  • 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?

    Thanks



  • 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
    projetoslinux@gmail.com

    thanks

    [quote author="RazZziel" date="1395676332"]Updated version for Qt 5.2.1: http://pastebin.com/k1u6gNe2[/quote]





  • Thank you very much RazZziel !!!!



  • Hi
    [quote author="RazZziel" date="1400018116"]This one shouldn't expire: http://pastebin.com/2A3EZQKA
    Nor this one: https://gist.github.com/RazZziel/fd607459c1f07a43cdf9[/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: http://pastebin.com/2A3EZQKA
    Nor this one: https://gist.github.com/RazZziel/fd607459c1f07a43cdf9

    After moving to qt.io 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
    Changes:
    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:

    #!/bin/bash
    
    # Based on http://qt-project.org/wiki/Build_Qt5_mysql_plugin_for_Android
    
    export ANDROID_NDK_ROOT="$HOME/.Qt/android-ndk-r10e/"
    export QT_ROOT="$HOME/.Qt/5.5/"
    
    SR="$ANDROID_NDK_ROOT/platforms/android-9/arch-arm/"
    BR="$ANDROID_NDK_ROOT/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin/arm-linux-androideabi-"
    
    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
    #pkg=openssl-1.0.1f.tar.gz
    #pkg=openssl-1.0.1e.tar.gz
    pkg=openssl-1.0.2d.tar.gz
    dir=$(basename $pkg .tar.gz)
    
    if [ ! -d $dir ]; then
            wget -c http://www.openssl.org/source/$pkg
            tar -xf $pkg || exit 1
    fi
    
    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
    popd
    
    
    # libiconv
    pkg=libiconv-1.14.tar.gz
    dir=$(basename $pkg .tar.gz)
    
    if [ ! -d $dir ]; then
            wget -c http://ftp.gnu.org/pub/gnu/libiconv/$pkg
            tar -xf $pkg || exit 1
    fi
    
    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
    popd
    
    
    # mariadbclient
    
    version=2.0.0
    pkg=mariadb_client-$version-src.tar.gz
    url=https://downloads.mariadb.org/f/client-native-$version/src/$pkg
    
    # FIXME: This one fails to build, linker errors
    #version=2.1.0
    #pkg=mariadb-connector-c-$version-src.tar.gz
    #url=https://downloads.mariadb.org/f/connector-c-$version/source-tgz/$pkg
    
    dir=$(basename $pkg .tar.gz)
    if [ ! -d $dir ]; then
            wget -c $url
            tar -xf $pkg || exit 1
    fi
    
    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_INSTALL_PREFIX="$SR/usr" \
    		-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" \
    		-DWITH_EXTERNAL_ZLIB=ON \
    		-DZLIB_INCLUDE_DIR="$SR/usr/include" \
    		-DZLIB_LIBRARY="$SR/usr/lib/libz.so" ../ || exit 1
            make install || exit 1
            popd
    
            # ???
            pwd
            cp build/libmariadb/*.{a,so} "$SR/usr/lib/mariadb/" || exit 1
    popd
    
    
    # qt
    qmake="$QT_ROOT/android_armv7/bin/qmake"
    [ ! -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)
    
    pkg=qt-everywhere-opensource-src-$qtVersion.tar.gz
    #pkg=qtbase-opensource-src-$qtVersion.tar.gz
    dir=$(basename $pkg .tar.gz)
    
    if [ ! -d $dir ]; then
    #        wget -c http://download.qt.io/official_releases/qt/${qtVersion%.*}/$qtVersion/submodules/$pkg
            wget -c http://download.qt.io/official_releases/qt/${qtVersion%.*}/$qtVersion/$pkg
            tar -xf $pkg || exit 1
    fi
    
    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 mysql.pro
            make || exit 1
            make install || exit 1
    popd
    
    
    echo
    echo "BOOYAH!!!"
    echo
    
    


  • I fixed this issue by using the following modifications
    https://gist.github.com/hpctech/a16f94f7ac3524d49219#file-buildandroidmysql-sh



  • Hi,

    Many thanks for "buildAndroidMysql.sh" !
    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
    TALL_PREFIX="$SR/usr" -DCMAKE_C_COMPILER="$BR"gcc -DCMAKE_LINKER="$BR"ld -DCMAKE_AR="$BR"ar -DCMAKE_NM="$BR"nm -DCMA
    KE_OBJCOPY="$BR"objcopy -DCMAKE_OBJDUMP="$BR"objdump -DCMAKE_RANLIB="$BR"ranlib -DCMAKE_STRIP="$BR"strip -DICONV_INC
    LUDE_DIR="$SR/usr/include" -DICONV_LIBRARIES="$SR/usr/lib/libiconv.a" -DWITH_EXTERNAL_ZLIB=ON -DZLIB_INCLUDE_DIR="$S
    R/usr/include" -DZLIB_LIBRARY="$SR/usr/lib/libz.so" ../
    

    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.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.