Prerequisites:
MSYSMinGW
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
This comment has been removed by the author.
ReplyDeleteUse the MinGW version that comes with Qt (/path/to/Qt/Tools/mingw482_32).
DeleteThis comment has been removed by the author.
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteThis comment has been removed by the author.
ReplyDeletehi,
ReplyDeletei get the following error message after i run cmake:
Check for working C compiler: c:/...arm-linux-androideabi-gcc.exe -- broken
i have no idea what i can do...
Thanks you very much for this article, but have have a error when in use "make" (after cmake .. -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Release \....) :
ReplyDelete"D:/Android/libs/MariaDB/include/my_global.h:76:62: fatal error: pthread.h: No such file or directory
#include /* AIX must have this included first */"
Thanks for you help.
Before make type:
Deleteecho $SR
ls "$SR"/*pthread*
What is the result?
Today when trying :
Delete$ cmake .. -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Release -DCMAKE_AR="$BR"ar.exe -DCMAKE_C_COMPILER="$BR"gcc.exe -DCMAK
E_C_FLAGS=--sysroot=$SR -DCMAKE_LINKER="$BR"ld.exe -DCMAKE_RANLIB="$BR"ranlib.exe -DCMAKE_STRIP="$BR"strip.exe -DWITH_E
XTERNAL_ZLIB=ON -DZLIB_INCLUDE_DIR=$SR/usr/include -DZLIB_LIBRARY=$SR/usr/lib/libz.so -DICONV_LIBRARIES=$ICONV_LIB -DCM
AKE_SYSTEM_NAME=Linux
-- Could NOT find Threads (missing: Threads_FOUND)
-- Could NOT find OpenSSL, try to set the path to OpenSSL root folder in the system variable OPENSSL_ROOT_DIR (missing: OPENSSL_LIBRARIES) (found version "1.1.0")
-- Configuring done
-- Generating done
-- Build files have been written to: D:/Android/libs/MariaDB
$ ls "$SR"/*pthread*
ReplyDeletels: /d/Android/Android-ndk/platforms/android-12/arch-arm/usr/*pthread*: No such file or directory
and
Deletels /d/Android/Android-ndk/platforms/
?
android-12 android-14 android-16 android-18 android-21 android-24 android-4 android-8
Deleteandroid-13 android-15 android-17 android-19 android-23 android-3 android-5 android-9
Do you see my message September 16, 2016 at 2:05 PM ?
So, in folder:
Delete/d/Android/Android-ndk/platforms/android-12/arch-arm/usr/
is there a file pthread.h ?
No...
Delete/d/Android/Android-ndk/platforms/android-12/arch-arm/usr/include, Yes !
Look inside android-14 or android-16 (and so on) for that file, and use that platform instead of android-12:
Deleteexport SR="$ANDROID_NDK_ROOT"/platforms/android-14/arch-arm/usr
All android-xx folders are empty. Only sub-folders 'include' and 'lib'...
DeleteI understand.. I'm sorry, but I can't help you.
DeleteTry to use android-ndk-r10b-win (the one used in this tutorial).
I have download http://dl.google.com/android/ndk/android-ndk32-r10b-windows-x86.zip.
DeleteI unzip to /d/Android/libs/ndk
I use export ANDROID_NDK_ROOT=/d/Android/libs/ndk
I have errors during cmake :
-- Could NOT find OpenSSL, try to set the path to OpenSSL root folder in the system variable OPENSSL_ROOT_DIR (missing: OPENSSL_LIBRARIES OPENSSL_INCLUDE_DIR)
-- Could NOT find Threads (missing: Threads_FOUND)
-- Looking for include file alloca.h
-- Looking for include file alloca.h - not found
-- Looking for include file arpa/inet.h
-- Looking for include file arpa/inet.h - not found
-- Looking for include file crypt.h
-- Looking for include file crypt.h - not found
-- Looking for include file dirent.h
-- Looking for include file dirent.h - not found
-- Looking for include file dlfcn.h
-- Looking for include file dlfcn.h - not found
-- Looking for include file execinfo.h
-- Looking for include file execinfo.h - not found
...
...
Idea ?
I really need MySQL plugin Android for my Qt 5.7.0 for my project. it's urgent
Many thanks.
Same problem... I try since 2 days.
DeleteMy project is now blocked. :(
Is not possible de find prebuild plugin for Qt 5.7.0 (android_armv7) ?
Many thanks.
I finally succeeded !
DeleteI had to base myself on the information presented here : http://pavelk.ru/tag/mysql
For this feature, I had to make changes.
Bye !
could you give me the file compiled to qt 5.7 please
DeleteThis comment has been removed by the author.
ReplyDeletewhenever i run cmake: than shown cmake:command not found in my MSYS console window
ReplyDelete