Prerequisites:
MSYS
MinGW
Android NDK
Cmake
Qt source code
Qt for Android
LibIconv source code
MariaDB Client Library source code
First, you need to download and build LibIconv (details
here), or you can download a prebuild version from
here.
Download and extract MariaDB Client Library.
Let's assume that we have the following directory structure:
Android NDK in: D:\tools\android\android-ndk-r10b-win
MinGW in: D:\tools\mingw482_32
Cmake in: D:\tools\cmake-2.8
Qt source code in: D:\tools\qtbase-opensource-src-5.3.2
Qt for Android in: D:\tools\Qt5.3.2\android_armv5
LibIconv header files in: D:\temp\android\libiconv-1.14_android\include
LibIconv lib file (libiconv.a) in: D:\temp\android\libiconv-1.14_android\lib
MariaDB Client Library in: D:\temp\android\mariadb_client-2.0.0-src
Go to MariaDB include subdirectory, D:\temp\android\mariadb_client-2.0.0-src\include .
Open my_global.h with a text editor and add:
#ifndef ushort
#define ushort uint16
#endif
Now open mariadb_client-2.0.0-src\libmariadb\CMakeLists.txt
Change:
INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include
${ZLIB_INC}
${CMAKE_SOURCE_DIR}/libmariadb)
to:
INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include
${ZLIB_INC}
${CMAKE_SOURCE_DIR}/libmariadb
"/d/temp/android/libiconv-1.14_android/include")
On line 175, change:
SET_TARGET_PROPERTIES(libmariadb PROPERTIES VERSION
${CPACK_PACKAGE_VERSION_MAJOR}
SOVERSION ${CPACK_PACKAGE_VERSION_MAJOR})
to:
#SET_TARGET_PROPERTIES(libmariadb PROPERTIES VERSION
# ${CPACK_PACKAGE_VERSION_MAJOR}
# SOVERSION ${CPACK_PACKAGE_VERSION_MAJOR})
Open a MSYS console.
Add MinGW and Cmake to PATH:
export PATH=$PATH:/d/tools/mingw482_32/bin
export PATH=$PATH:/d/tools/cmake-2.8/bin
Set the enviroment variables:
export ICONV_LIB=/d/temp/android/libiconv-1.14_android/lib/libiconv.a
export ANDROID_NDK_ROOT=/d/tools/android/android-ndk-r10b-win
export SR="$ANDROID_NDK_ROOT"/platforms/android-12/arch-arm/usr
export BR="$ANDROID_NDK_ROOT"/toolchains/arm-linux-androideabi-4.8/prebuilt/windows/bin/arm-linux-androideabi-
Go to MariaDB directory:
cd /d/temp/android/mariadb_client-2.0.0-src
mkdir build && cd build
Run cmake:
cmake .. -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Release \
-DCMAKE_AR="$BR"ar.exe \
-DCMAKE_C_COMPILER="$BR"gcc.exe \
-DCMAKE_C_FLAGS=--sysroot=$SR \
-DCMAKE_LINKER="$BR"ld.exe \
-DCMAKE_RANLIB="$BR"ranlib.exe \
-DCMAKE_STRIP="$BR"strip.exe \
-DWITH_EXTERNAL_ZLIB=ON \
-DZLIB_INCLUDE_DIR=$SR/usr/include \
-DZLIB_LIBRARY=$SR/usr/lib/libz.so \
-DICONV_LIBRARIES=$ICONV_LIB \
-DCMAKE_SYSTEM_NAME=Linux
Build:
make
Rename the lib:
mv libmariadb/libmariadbclient.a libmariadb/libmysqlclient.a
Now, let's build the plugin
mkdir QtMySqlDriver && cd QtMySqlDriver
/d/tools/Qt5.3.2/android_armv5/bin/qmake.exe \
/d/tools/qtbase-opensource-src-5.3.2/src/plugins/sqldrivers/mysql/mysql.pro \
INCLUDEPATH+="../include ../../include" \
LIBPATH+="/d/temp/android/libiconv-1.14_android/lib ../libmariadb" \
LIBS+="-lmysqlclient -liconv"
make
Move libqsqlmysql.so into QtInstallDir/plugins/sqldrivers (D:\tools\Qt5.3.2\android_armv5\plugins\sqldrivers).
Now androiddeployqt tool will bundle the plugin with the app.
You can download the prebuild plugin
here (
libqsqlmysql.7z 544 KB).
Here is a sample app running on Android 2.3:
Downloads:
Sample Android app (
TestMYSQL.apk) 6,95 MB
Sample app source code (
TestMYSQL-src.7z) 2,36 KB