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. How to build MySQL driver for Android?
Forum Updated to NodeBB v4.3 + New Features

How to build MySQL driver for Android?

Scheduled Pinned Locked Moved Unsolved Mobile and Embedded
53 Posts 6 Posters 20.8k Views 3 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.
  • M Maestro Evil

    @aha_1980 Happy New Year! This file does not exist. It can be taken from the source of mysql server?
    0_1514823245024_puck.png

    aha_1980A Offline
    aha_1980A Offline
    aha_1980
    Lifetime Qt Champion
    wrote on last edited by
    #4

    @Maestro-Evil

    If I read the tutorial you linked, there is one step mentioned:

    qmake „INCLUDEPATH+=%mysql%\\include“ „LIBS+=%mysql%\\lib\\libmysql.lib“ -o Makefile mysql.pro

    Here you specify the path to the include directory of the MySQL server (client) library. I guess you have a problem here so the compiler cannot find mysql.h during compilation.

    Also, as noted there, take care with spaces in the path names!

    Qt has to stay free or it will die.

    M 1 Reply Last reply
    1
    • aha_1980A aha_1980

      @Maestro-Evil

      If I read the tutorial you linked, there is one step mentioned:

      qmake „INCLUDEPATH+=%mysql%\\include“ „LIBS+=%mysql%\\lib\\libmysql.lib“ -o Makefile mysql.pro

      Here you specify the path to the include directory of the MySQL server (client) library. I guess you have a problem here so the compiler cannot find mysql.h during compilation.

      Also, as noted there, take care with spaces in the path names!

      M Offline
      M Offline
      Maestro Evil
      wrote on last edited by
      #5

      @aha_1980 This problem was solved, but at the last stage a new error is formed.0_1514824189607_error2.png

      aha_1980A 1 Reply Last reply
      0
      • M Maestro Evil

        @aha_1980 This problem was solved, but at the last stage a new error is formed.0_1514824189607_error2.png

        aha_1980A Offline
        aha_1980A Offline
        aha_1980
        Lifetime Qt Champion
        wrote on last edited by
        #6

        @Maestro-Evil Seems like you now have the same problem at the linker stage: now you need to make sure the linker can find libmysql (extension should be .a or .so)

        I cannot really help you here as I don't have Windows and never build the MySQL plugin...

        Qt has to stay free or it will die.

        M 1 Reply Last reply
        0
        • aha_1980A aha_1980

          @Maestro-Evil Seems like you now have the same problem at the linker stage: now you need to make sure the linker can find libmysql (extension should be .a or .so)

          I cannot really help you here as I don't have Windows and never build the MySQL plugin...

          M Offline
          M Offline
          Maestro Evil
          wrote on last edited by
          #7

          @aha_1980 thank you

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

            Hi,

            Something is not clear here, your title implies that you are trying to build for Android yet you follow instructions for building desktop version of the plugin.

            So what is your end goal ?

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

            M 1 Reply Last reply
            0
            • SGaistS SGaist

              Hi,

              Something is not clear here, your title implies that you are trying to build for Android yet you follow instructions for building desktop version of the plugin.

              So what is your end goal ?

              M Offline
              M Offline
              Maestro Evil
              wrote on last edited by
              #9

              @SGaist hi. I want build MySQL driver for Android. PLZ HELP)

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

                Read this Wiki article

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

                M 1 Reply Last reply
                2
                • SGaistS SGaist

                  Read this Wiki article

                  M Offline
                  M Offline
                  Maestro Evil
                  wrote on last edited by
                  #11

                  @SGaist Will this work for Windows?

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

                    Since the scripts provided are in bash, you might have some trouble to do that as presented. If that would be the case, then you can still install a virtual machine with Linux on it.

                    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
                    • A Offline
                      A Offline
                      Allerknappe
                      wrote on last edited by Allerknappe
                      #13
                      This post is deleted!
                      1 Reply Last reply
                      0
                      • A Offline
                        A Offline
                        Allerknappe
                        wrote on last edited by
                        #14

                        i have a similar problem.
                        i try the option 2 instruction of the wiki article with MSYS on windows.

                        it also runs a few lines and then i get following error:
                        0_1515410775397_fail.jpg

                        i have used this shell script modified to my system:

                        #!/bin/bash
                        # Usage: ./build_libsqlmariadb.so.sh [clean]
                        # 2016-07-22 T-bond (https://t-bond.hu) Added Windows-MSYS build support, Added clean option, and output to dir. Added temp build dir. Fixed no getpwent error. More cleaner compile output. Skip for already built libs
                        
                        # Based on https://gist.github.com/RazZziel/fd607459c1f07a43cdf9
                        output_dir="libmariadb_so_output"
                        build_dir="build_libmariadb_temp"
                        
                        export ANDROID_NDK_ROOT="/c/users/allerknappe/appdata/local/android/sdk/ndk-bundle"
                        export QT_ROOT="/c/Qt/5.7"
                         
                        SR="$ANDROID_NDK_ROOT/platforms/android-17/arch-arm/"
                        BR="$ANDROID_NDK_ROOT/toolchains/arm-linux-androideabi-4.9/prebuilt/windows-x86_64/bin/arm-linux-androideabi-"
                        no_skips=true
                        
                        #Clean build and outputs
                        if [ "$1" = "clean" ]; then
                        	echo "Cleaning..."
                        	rm -r -f $build_dir $output_dir
                        	echo "Cleaned."
                        else
                        pushd () {
                            command pushd "$@" > /dev/null
                        }
                        
                        popd () {
                            command popd "$@" > /dev/null
                        }
                        
                        if [ ! -d $build_dir ]; then
                        mkdir $build_dir
                        fi
                        pushd $build_dir
                         
                        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.2h.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
                        		if [ ! -f "skip" ] || [ "$no_skips" = true ]; then
                        	        RANLIB="$BR"ranlib CC="$BR"gcc ./Configure android-armv7 --prefix=$SR/usr
                        	        ANDROID_DEV=$SR/usr make || exit 1
                        	        make build_libs || exit 1
                                touch skip
                            	fi
                        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
                        		if [ ! -f "skip" ] || [ "$no_skips" = true ]; then
                        			#Fix for outdated scripts on Windows T-bond.
                        			wget "http://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.guess;hb=HEAD" -O new_config.guess
                        			wget "http://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.sub;hb=HEAD" -O new_config.sub
                        			\cp new_config.guess build-aux/config.guess
                        			\cp new_config.guess libcharset/build-aux/config.guess
                        			\cp new_config.sub build-aux/config.sub
                        			\cp new_config.sub libcharset/build-aux/config.sub
                        			#Fix for outdated scripts on Windows T-bond. END
                        			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
                        	        touch skip
                            	fi
                        popd
                         
                         
                        # mariadbclient
                         
                        version=2.0.0
                        pkg=mariadb_client-$version-src.tar.gz
                        url=http://archive.mariadb.org/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
                        		if [ ! -f "skip" ] || [ "$no_skips" = true ]; then
                        	        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
                        	        sed -i '/#ifdef HAVE_GETPWNAM/c#if defined(HAVE_GETPWNAM) && defined(HAVE_GETPWENT)' libmariadb/mf_pack.c #T-bond: Fix the no getpwent error. http://forum.kodi.tv/showthread.php?tid=280134
                        	        #DCMAKE_CXX_COMPILER DCMAKE_SYSTEM_VERSION DCMAKE_SYSTEM_NAME WINDOWS ONLY!!!
                        	        if [ ! -d "build" ]; then
                        	        	mkdir build
                        	    	fi
                        	        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_SYSTEM_NAME="Android" \
                        			-DCMAKE_SYSTEM_VERSION=1 \
                        			-DCMAKE_CXX_COMPILER="$BR"g++ \
                        			-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
                        	        cp build/libmariadb/*.{a,so} "$SR/usr/lib/mariadb/" || exit 1
                        	        touch skip
                        	    fi
                        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=5.7.0
                        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
                                tar -xf $pkg || exit 1
                        fi
                         
                        pushd $dir/src/plugins/sqldrivers/mysql/
                        		$qmake "QMAKE_CXX=$BR"g++ "QMAKE_LINK=$BR"g++ "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 
                        popd
                        
                        if [ ! -d $output_dir ]; then
                        	mkdir $output_dir
                        fi
                        cp $SR/usr/lib/mariadb/libmariadb.so $output_dir/libmariadb.so
                        cp $QT_ROOT/android_armv7/plugins/sqldrivers/libqsqlmysql.so $output_dir/libqsqlmysql.so
                         
                        echo
                        echo "BOOYAH!!!"
                        echo
                        fi
                        

                        for some help im really grateful.

                        1 Reply Last reply
                        0
                        • L Offline
                          L Offline
                          Leonardo
                          wrote on last edited by
                          #15

                          Download the source code for libmysqlclient.

                          https://dev.mysql.com/downloads/connector/c/

                          Get MSYS2 for Windows. Get cmake. Cross compile the mysql client library using cmake and the GCC for Android you have. Make sure to enable the static output, so later you can build a self contained plugin.

                          Now you have the static library "libmysqlclient.a" and all include files on the output directory you specified on cmake. When configuring Qt, add the flags for additional include directory (-I) and library directory (-L) using the paths you have. And that's it.

                          I would also compile Qt for Android using MSYS2 and not Windows Prompt. The "configure" shell script seems to be smarter than the ".bat" one.

                          1 Reply Last reply
                          0
                          • A Offline
                            A Offline
                            Allerknappe
                            wrote on last edited by
                            #16

                            @Leonardo said in How to build MySQL driver for Android?:

                            MSYS2

                            ok at first, thanks for the answer.
                            but sorry for the question, but how i cross compile the mysql client library using cmake and the GCC for Android and enable the static output ? should not the shell script do it for me?

                            I try already to use the shell script with msys 1.0( not 2) the picture with the error above is msys (not a .bat with the windows prompt)

                            1 Reply Last reply
                            0
                            • A Offline
                              A Offline
                              Allerknappe
                              wrote on last edited by
                              #17

                              so i try the option 1 in the mysql plugin wiki

                              i get a problem with cmake, with the following output:

                              0_1515514244863_fail2.jpg

                              so on, here the cmakeoutput.log:

                              The system is: Windows - 10.0.16299 - AMD64
                              Compiling the C compiler identification source file "CMakeCCompilerId.c" succeeded.
                              Compiler: c:/users/allerknappe/appdata/local/android/sdk/ndk-bundle/toolchains/arm-linux-androideabi-4.9/prebuilt/windows-x86_64/bin/arm-linux-androideabi-gcc 
                              Build flags: --sysroot=c:/users/allerknappe/appdata/local/android/sdk/ndk-bundle/platforms/android-9/arch-arm
                              Id flags:  
                              
                              The output was:
                              0
                              
                              
                              Compilation of the C compiler identification source "CMakeCCompilerId.c" produced "a.out"
                              
                              The C compiler identification is GNU, found in "C:/temp/android/mariadb_client-2.0.0-src/build/CMakeFiles/3.10.1/CompilerIdC/a.out"
                              

                              i was runing this self writen instruction with code in msys1.0, in msys2 it seems to be not working:

                              first install msys2 and then grep
                              
                              SR=/c/users/allerknappe/appdata/local/android/sdk/ndk-bundle/platforms/android-9/arch-arm
                              BR=/c/users/allerknappe/appdata/local/android/sdk/ndk-bundle/toolchains/arm-linux-androideabi-4.9/prebuilt/windows-x86_64/bin/arm-linux-androideabi-
                              
                              cd #to openssl1.0.1e
                              
                              RANLIB="$BR"ranlib CC="$BR"gcc ./Configure android-armv7 --prefix=$SR/usr
                              ANDROID_DEV=$SR/usr make		
                              make install
                              
                              cd /c/temp/android/libiconv-1.14_android
                              
                              STRIP="$BR"strip RANLIB="$BR"ranlib OBJDUMP="$BR"objdump AR="$BR"ar CC="$BR"gcc CFLAGS=--sysroot=$SR CPP="$BR"cpp CPPFLAGS=$CFLAGS ./configure --build=x86_64 --host=arm --prefix=$SR/usr --with-sysroot=$SR && make install
                              
                              cd /c/temp/android/mariadb_client-2.0.0-src
                              
                              mkdir build && cd build
                              
                              #Fail in the line after 
                              PKG_CONFIG_PATH=$SR/usr/lib/pkgconfig cmake -DCMAKE_AR="$BR"ar -DCMAKE_BUILD_TYPE=Release -DCMAKE_C_COMPILER="$BR"gcc -DCMAKE_C_FLAGS=--sysroot=$SR -DCMAKE_INSTALL_PREFIX=$SR/usr -DCMAKE_LINKER="$BR"ld -DCMAKE_NM="$BR"nm -DCMAKE_OBJCOPY="$BR"objcopy -DCMAKE_OBJDUMP="$BR"objdump -DCMAKE_RANLIB="$BR"ranlib -DCMAKE_STRIP="$BR"strip -DWITH_EXTERNAL_ZLIB=ON -DICONV_INCLUDE_DIR=$SR/usr/include -DICONV_LIBRARIES=$SR/usr/lib/libiconv.a -DZLIB_INCLUDE_DIR=$SR/usr/include -DZLIB_LIBRARY=$SR/usr/lib/libz.so ../
                              
                              #in include/my_global.h inside the #define _global_h block: 
                              #ifndef ushort
                              #define ushort uint16
                              #endif
                              
                              make install
                              "$BR"objdump -p libqsqlmysql.so | grep NEEDED
                              
                              #edit libmariadb/CMakeLists.txt and comment out the block: 
                              #SET_TARGET_PROPERTIES(libmariadb PROPERTIES VERSION ${CPACK_PACKAGE_VERSION_MAJOR} SOVERSION ${CPACK_PACKAGE_VERSION_MAJOR})
                              
                              You've to add an external library to your .pro file because the generated plugin depends on libmariadb.so
                              
                              contains(ANDROID_TARGET_ARCH,armeabi-v7a) {
                                  ANDROID_EXTRA_LIBS = \
                                      # modify the path
                                      $$PWD/../../../mysqllibandroid/mariadb_client-2.0.0-src/build/libmariadb/libmariadb.so
                              }
                              
                              

                              is maybe something with cmake wrong? but when yes, what?

                              1 Reply Last reply
                              0
                              • L Offline
                                L Offline
                                Leonardo
                                wrote on last edited by
                                #18

                                The "configure" from Qt builds the MySQL plugin for Qt. The plugin depends on libmysqlclient, which you should build separately.

                                Get cmake binaries here:

                                https://cmake.org/download/

                                I'm assuming you may not be used to compiling using a shell. The download above has a GUI with a wizard that might help you cross compile. Use it to generate the Makefile. Then go on msys and type "make".

                                I have never used the mariadb client. I can only help you with libmysqlclient.

                                1 Reply Last reply
                                0
                                • A Offline
                                  A Offline
                                  Allerknappe
                                  wrote on last edited by
                                  #19

                                  ok thanks for the answer.
                                  i tried the last 3 days to make the Driver for Android but the hole scrips and different versions that maybe not working together working for me all not together....
                                  do you can give me a step by step instruction to configure the mysql plugin till the end when i try to make? maybe for you is it easy, but i´m dont know what i will do...

                                  1 Reply Last reply
                                  0
                                  • L Offline
                                    L Offline
                                    Leonardo
                                    wrote on last edited by
                                    #20

                                    It's been a while since I've done this process. I was repeating it now to write a step by step tutorial to you and it's much more painful than I could remember... There are many errors and patches to apply along the process. I think it's just easier to share the binary I have obtained with you. I see you're using GCC 4.9. I've used 4.8. Maybe it still works.

                                    https://www.dropbox.com/s/e6ejk3nj1xljzs2/mysql-connector-android.7z?dl=0

                                    When building Qt, just add the following flags:

                                    configure ... -plugin-sql-mysql -I C:/path/to/mysql-connector-android/include -L C:/path/to/mysql-connector-android/lib/

                                    1 Reply Last reply
                                    1
                                    • A Offline
                                      A Offline
                                      Allerknappe
                                      wrote on last edited by
                                      #21

                                      ok im really gratefull for your source, so i try on.
                                      After i run the configure statement i got this output:
                                      0_1515567612077_fail3.jpg
                                      later i also try to run cmake but i got also an error...

                                      1 Reply Last reply
                                      0
                                      • A Offline
                                        A Offline
                                        Allerknappe
                                        wrote on last edited by Allerknappe
                                        #22

                                        ok i think i have to set the -xplatform android-g++ option.
                                        if i try this i will answer...

                                        update:
                                        i run the configure command in the ms prompt and there it should work...
                                        have i then do additional things? or can i run in the same directory as configure is the make command and thats it? get i then a new .so file for the arch-armv7 folder?

                                        1 Reply Last reply
                                        0
                                        • A Offline
                                          A Offline
                                          Allerknappe
                                          wrote on last edited by
                                          #23

                                          ok i try another few things but still an error. It´s maybe possible to take a workable libqsqlmysql.so from an other user for my qt 5.7 ?
                                          I have only found a version for qt 5.3.2 and i´m thinking about to downgrade qt if i don´t get another solution...

                                          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