Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

MYSQL DRIVER ANDROID



  • Hi to everyone! I try to build MYSQL for Android using a Option 2 (https://wiki.qt.io/Build_Qt_5_MySQL_Plugin_for_Android)

    This is my .sh file.

    #!/bin/bash
    
    # Based on http://qt-project.org/wiki/Build_Qt5_mysql_plugin_for_Android
    
    export ANDROID_NDK_ROOT="$HOME/Documenti/android-ndk-r10e"
    export QT_ROOT="$HOME/Qt/5.11.1"
    
    SR="$ANDROID_NDK_ROOT/platforms/android-21/arch-arm"
    BR="$ANDROID_NDK_ROOT/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86/bin/arm-linux-androideabi-"
    
    no_skips=false
    
    #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
    

    but it fails.. Return this error:

    make[1]: /home/edoardo/Documenti/android-ndk-r10e/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86/bin/arm-linux-androideabi-gcc: Command not found
    <incorporato>: recipe for target 'cryptlib.o' failed
    make[1]: *** [cryptlib.o] Error 127
    make[1]: uscita dalla directory "/home/edoardo/Documenti/openssl-1.0.2h/crypto"
    Makefile:284: recipe for target 'build_crypto' failed
    
    

    Someone can help me? It's enough for me to have the libqsqlmysql.so
    Thank so much!



  • @edoardo.videx

    /home/edoardo/Documenti/android-ndk-r10e/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86/bin/arm-linux-androideabi-gcc: Command not found

    check this error, no compiler found when building OpenSSL...



  • @Pablo-J.-Rogina Okay, now works, but now i have this error:

    Cannot read /home/edoardo/Scrivania/qtbase-opensource-src-5.9.7/src/plugins/sqldrivers/qtsqldrivers-config.pri: No such file or directory
    
    
    


  • @edoardo.videx Internet seach is your friend...

    it looks like there was (is?) a bug with out-of-tree build of SQL plugins in Qt since version 5.8 see for instance QTBUG-58372 and check how a manual build could be enabled.


Log in to reply