Build Qt 5 MySQL Plugin for Android: Difference between revisions

From Qt Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
Line 1: Line 1:
[toc align_right="yes" depth="2"]
[toc align_right="yes" depth="2"]


= Overview =
= Overview =
Line 28: Line 28:
First, grab the sources and unpack them. Then, enter the source directory and do the following:
First, grab the sources and unpack them. Then, enter the source directory and do the following:


<code>RANLIB=&quot;$BR&amp;quot;ranlib CC=&quot;$BR&amp;quot;gcc ./Configure android-armv7 —prefix=$SR/usr<br />ANDROID_DEV=$SR/usr make<br />make install</code>
<code>RANLIB="$BR"ranlib CC="$BR"gcc ./Configure android-armv7 —prefix=$SR/usr
ANDROID_DEV=$SR/usr make
make install</code>


Note: There should be a way to get openssl to compile and install only the library, but I haven't found the right make targets for that yet. The above will make and install everything for openssl rather than just the library.
Note: There should be a way to get openssl to compile and install only the library, but I haven't found the right make targets for that yet. The above will make and install everything for openssl rather than just the library.
Line 40: Line 42:
First, grab the sources and unpack them. Then, enter the source directory and do the following:
First, grab the sources and unpack them. Then, enter the source directory and do the following:


</code>STRIP=&quot;$BR&amp;quot;strip RANLIB=&quot;$BR&amp;quot;ranlib OBJDUMP=&quot;$BR&amp;quot;objdump AR=&quot;$BR&amp;quot;ar CC=&quot;$BR&amp;quot;gcc CFLAGS=—sysroot=$SR CPP=&quot;$BR&amp;quot;cpp CPPFLAGS=$CFLAGS ./configure —build=x86_64 —host=arm —prefix=$SR/usr —with-sysroot=$SR &amp;&amp; make install</code>
</code>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 &amp;&amp; make install</code>


== Compiling mariadbclient (Option 1) ==
== Compiling mariadbclient (Option 1) ==
Line 46: Line 48:
After testing, I've found that the released sources are not compatible with mysql (as of version 1.0.0). They are missing the mysql_library_init function, which the Qt mysql plugin uses. However, the bazaar sources are compatible with mysql and include this function. Grab the mariadb sources from bazaar, configure, compile, and install the mariadb connector client library as described below:
After testing, I've found that the released sources are not compatible with mysql (as of version 1.0.0). They are missing the mysql_library_init function, which the Qt mysql plugin uses. However, the bazaar sources are compatible with mysql and include this function. Grab the mariadb sources from bazaar, configure, compile, and install the mariadb connector client library as described below:


<code>bzr branch lp:mariadb-native-client<br />cd maria-native-client</code>
<code>bzr branch lp:mariadb-native-client
cd maria-native-client</code>


The mariadb unit tests will fail and halt the compilation of maria db due to some missing pthread routines. I recommend commenting out the unit tests so they don't block the install. Modify CMakeLists.txt in the base source directory and comment out the following line:
The mariadb unit tests will fail and halt the compilation of maria db due to some missing pthread routines. I recommend commenting out the unit tests so they don't block the install. Modify CMakeLists.txt in the base source directory and comment out the following line:
Line 56: Line 59:
Now you can configure via cmake:
Now you can configure via cmake:


</code>mkdir build &amp;&amp; cd build<br />PKG_CONFIG_PATH=$SR/usr/lib/pkgconfig cmake -DCMAKE_AR=&quot;$BR&amp;quot;ar -DCMAKE_BUILD_TYPE=Release -DCMAKE_C_COMPILER=&quot;$BR&amp;quot;gcc -DCMAKE_C_FLAGS=—sysroot=$SR -DCMAKE_INSTALL_PREFIX=$SR/usr -DCMAKE_LINKER=&quot;$BR&amp;quot;ld -DCMAKE_NM=&quot;$BR&amp;quot;nm -DCMAKE_OBJCOPY=&quot;$BR&amp;quot;objcopy -DCMAKE_OBJDUMP=&quot;$BR&amp;quot;objdump -DCMAKE_RANLIB=&quot;$BR&amp;quot;ranlib -DCMAKE_STRIP=&quot;$BR&amp;quot;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 ../<code>
</code>mkdir build &amp;&amp; cd build
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 ../<code>


At this point, you'll want to make some minor changes to the sources to make them compile on android. For one, the android compiler does not know what a 'ushort' is. So, define it in include/my_global.h inside the #define _global_h block:
At this point, you'll want to make some minor changes to the sources to make them compile on android. For one, the android compiler does not know what a 'ushort' is. So, define it in include/my_global.h inside the #define _global_h block:


</code>#ifndef ushort<br />#define ushort uint16<br />#endif<code>
</code>#ifndef ushort
#define ushort uint16
#endif<code>


Now you're ready to compile and install:
Now you're ready to compile and install:
Line 68: Line 74:
=== Deployment Notes ===
=== Deployment Notes ===


You will need to add the mariadb shared object library file the list of additional libraries to add to the APK image. To get the exact name of the file needed after compiling the QT mysql plugin use the following command:<br /><code>&quot;$BR&amp;quot;objdump <s>p libqsqlmysql.so | grep NEEDED<code>
You will need to add the mariadb shared object library file the list of additional libraries to add to the APK image. To get the exact name of the file needed after compiling the QT mysql plugin use the following command:
<br />To correctly create a mariadb.so file instead of mariadb.so.1 edit libmariadb/CMakeLists.txt and comment out the block:<br /></code> SET_TARGET_PROPERTIES(libmariadb PROPERTIES VERSION ${CPACK_PACKAGE_VERSION_MAJOR} SOVERSION ${CPACK_PACKAGE_VERSION_MAJOR})</code>
<code>"$BR"objdump -p libqsqlmysql.so | grep NEEDED<code>
<br />h2. Compiling mysqlclient (Option 2)
 
<br />p. Stub for someone to experiment with and update this page
To correctly create a mariadb.so file instead of mariadb.so.1 edit libmariadb/CMakeLists.txt and comment out the block:
<br />h1. Compiling the Qt mysql plugin
</code> SET_TARGET_PROPERTIES(libmariadb PROPERTIES VERSION ${CPACK_PACKAGE_VERSION_MAJOR} SOVERSION ${CPACK_PACKAGE_VERSION_MAJOR})</code>
<br />p. You cannot compile the mysql plugin from the configure script for android</s> that appears to be broken as of this writing. You can, however, compile it manually from the sources. Grab the Qt5 sources from git, configure them for android as normal (without the qt-sql-mysql or plugin-sql-mysql flags), make, and install as normal. Then enter the qtbase/src/plugins/sqldrivers/mysql directory and execute the following:
 
h2. Compiling mysqlclient (Option 2)
 
p. Stub for someone to experiment with and update this page
 
h1. Compiling the Qt mysql plugin
 
p. You cannot compile the mysql plugin from the configure script for android- that appears to be broken as of this writing. You can, however, compile it manually from the sources. Grab the Qt5 sources from git, configure them for android as normal (without the qt-sql-mysql or plugin-sql-mysql flags), make, and install as normal. Then enter the qtbase/src/plugins/sqldrivers/mysql directory and execute the following:

Revision as of 09:47, 25 February 2015

[toc align_right="yes" depth="2"]

Overview

Building the Qt5 mysql plugin for Android turned out to not be as straightforward as you may hope. I'll cover the necessary steps to accomplish this below.

Setting up the general environment

Set the following environment variables:

  1. SR=/path/to/android/ndk/platforms/android-9/arch-arm
  2. BR=/path/to/android/ndk/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin/arm-linux-androideabi-

NOTE: I have been unable to get openssl to compile on the x86 version of android, hence the ARMv7 variables above. If you are successful at getting openssl to compile with the x86 android, by all means update this wiki :).

Prerequisites

The mysql module requires the following to compile:

  1. The mysql client library. For mariadb (recommended mysql implementation), you also require:
    1. openssl
    2. libiconv

Compiling OpenSSL

I've tested this with openssl version 1.0.1e. This should work with future versions as well, but I can't guarantee that.

First, grab the sources and unpack them. Then, enter the source directory and do the following:

RANLIB="$BR"ranlib CC="$BR"gcc ./Configure android-armv7 prefix=$SR/usr
ANDROID_DEV=$SR/usr make
make install

Note: There should be a way to get openssl to compile and install only the library, but I haven't found the right make targets for that yet. The above will make and install everything for openssl rather than just the library.

To install only the binary files use

make install_sw<code>

== Compiling libiconv ==

I've tested this with libiconv version 1.14. Again, this should work with future versions, but I can't guarantee as much.

First, grab the sources and unpack them. Then, enter the source directory and do the following:

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

Compiling mariadbclient (Option 1)

After testing, I've found that the released sources are not compatible with mysql (as of version 1.0.0). They are missing the mysql_library_init function, which the Qt mysql plugin uses. However, the bazaar sources are compatible with mysql and include this function. Grab the mariadb sources from bazaar, configure, compile, and install the mariadb connector client library as described below:

bzr branch lp:mariadb-native-client
cd maria-native-client

The mariadb unit tests will fail and halt the compilation of maria db due to some missing pthread routines. I recommend commenting out the unit tests so they don't block the install. Modify CMakeLists.txt in the base source directory and comment out the following line:

ADD_SUBDIRECTORY(unittest/libmariadb)<code>

UPDATE: As of connector version 2.0.0, mariadb is fully compatible with the released version. If you download the 2.0.0 (or later) connector, you can start from this point. You will not need the bazaar sources, nor will you need to disable the unit tests above.

Now you can configure via cmake:

mkdir build && cd build 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 ../

At this point, you'll want to make some minor changes to the sources to make them compile on android. For one, the android compiler does not know what a 'ushort' is. So, define it in include/my_global.h inside the #define _global_h block:

#ifndef ushort

  1. define ushort uint16
  2. endif
    Now you're ready to compile and install:
    
    make install

Deployment Notes

You will need to add the mariadb shared object library file the list of additional libraries to add to the APK image. To get the exact name of the file needed after compiling the QT mysql plugin use the following command:

"$BR"objdump -p libqsqlmysql.so | grep NEEDED<code>

To correctly create a mariadb.so file instead of mariadb.so.1 edit libmariadb/CMakeLists.txt and comment out the block:

SET_TARGET_PROPERTIES(libmariadb PROPERTIES VERSION ${CPACK_PACKAGE_VERSION_MAJOR} SOVERSION ${CPACK_PACKAGE_VERSION_MAJOR})

h2. Compiling mysqlclient (Option 2)

p. Stub for someone to experiment with and update this page

h1. Compiling the Qt mysql plugin

p. You cannot compile the mysql plugin from the configure script for android- that appears to be broken as of this writing. You can, however, compile it manually from the sources. Grab the Qt5 sources from git, configure them for android as normal (without the qt-sql-mysql or plugin-sql-mysql flags), make, and install as normal. Then enter the qtbase/src/plugins/sqldrivers/mysql directory and execute the following: