How to build MySQL driver for Android?
-
wrote on 1 Jan 2018, 11:44 last edited by A Former User 1 Jan 2018, 14:02
Hello people. I'm trying to build a mysql driver for Android with the help of this instruction link text , but it produces errors. Help to solve the problem or give a link to another instruction.
-
Hello people. I'm trying to build a mysql driver for Android with the help of this instruction link text , but it produces errors. Help to solve the problem or give a link to another instruction.
As you can see, it fails including
mysql.h
. Do you have this file? Is the compiler able to find it during the driver compilation?Happy New Year!
-
As you can see, it fails including
mysql.h
. Do you have this file? Is the compiler able to find it during the driver compilation?Happy New Year!
wrote on 1 Jan 2018, 16:14 last edited by@aha_1980 Happy New Year! This file does not exist. It can be taken from the source of mysql server?
-
@aha_1980 Happy New Year! This file does not exist. It can be taken from the source of mysql server?
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!
-
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!
wrote on 1 Jan 2018, 16:29 last edited by@aha_1980 This problem was solved, but at the last stage a new error is formed.
-
@aha_1980 This problem was solved, but at the last stage a new error is formed.
@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...
-
@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...
wrote on 1 Jan 2018, 16:39 last edited by@aha_1980 thank you
-
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 ?
-
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 ?
wrote on 1 Jan 2018, 19:38 last edited by@SGaist hi. I want build MySQL driver for Android. PLZ HELP)
-
Read this Wiki article
-
Read this Wiki article
wrote on 1 Jan 2018, 20:07 last edited by@SGaist Will this work for Windows?
-
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.
-
wrote on 7 Jan 2018, 22:40 last edited by Allerknappe 1 Aug 2018, 11:41This post is deleted!
-
wrote on 8 Jan 2018, 11:41 last edited by
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:
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.
-
wrote on 8 Jan 2018, 21:20 last edited by
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.
-
wrote on 9 Jan 2018, 09:57 last edited by
@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)
-
wrote on 9 Jan 2018, 16:15 last edited by
so i try the option 1 in the mysql plugin wiki
i get a problem with cmake, with the following output:
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?
-
wrote on 9 Jan 2018, 19:23 last edited by
The "configure" from Qt builds the MySQL plugin for Qt. The plugin depends on libmysqlclient, which you should build separately.
Get cmake binaries here:
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.
-
wrote on 9 Jan 2018, 22:17 last edited by
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... -
wrote on 9 Jan 2018, 23:39 last edited by
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/53