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:
=Overview=
[toc align_right="yes" depth="2"]


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.
= Overview =


=Setting up the general environment=
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:
Set the following environment variables:
Line 10: Line 12:
# BR=/path/to/android/ndk/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin/arm-linux-androideabi-
# BR=/path/to/android/ndk/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin/arm-linux-androideabi-


<span class="caps">NOTE</span>: 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 :).
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=
= Prerequisites =


The mysql module requires the following to compile:
The mysql module requires the following to compile:
Line 20: Line 22:
## libiconv
## libiconv


==Compiling OpenSSL==
== 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.
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:
First, grab the sources and unpack them. Then, enter the source directory and do the following:


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.
<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>
 
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 <code>make install_sw<code>


==Compiling libiconv==
== 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.
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:
First, grab the sources and unpack them. Then, enter the source directory and do the following:


==Compiling mariadbclient (Option 1)==
</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>
 
== 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:
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:


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:
<code>bzr branch lp:mariadb-native-client<br />cd maria-native-client</code>


<span class="caps">UPDATE</span>: 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.
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:


Now you can configure via cmake:
<code>ADD_SUBDIRECTORY(unittest/libmariadb)<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:
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’re ready to compile and install:
Now you can configure via cmake:


===Deployment Notes===
</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>


You will need to add the mariadb shared object library file the list of additional libraries to add to the <span class="caps">APK</span> image. To get the exact name of the file needed after compiling the QT mysql plugin use the following command:<br />
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:


To correctly create a mariadb.so file instead of mariadb.so.1 edit libmariadb/CMakeLists.txt and comment out the block:<br />
</code>#ifndef ushort<br />#define ushort uint16<br />#endif<code>


==Compiling mysqlclient (Option 2)==
Now you're ready to compile and install:


Stub for someone to experiment with and update this page
</code>make install</code>


=Compiling the Qt mysql plugin=
=== Deployment Notes ===


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:
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>
<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>
<br />h2. Compiling mysqlclient (Option 2)
<br />p. Stub for someone to experiment with and update this page
<br />h1. Compiling the Qt mysql plugin
<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:

Revision as of 09:25, 24 February 2015

[toc align_right="yes&quot; depth="2&quot;]

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=&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

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&quot;strip RANLIB="$BR&quot;ranlib OBJDUMP="$BR&quot;objdump AR="$BR&quot;ar CC="$BR&quot;gcc CFLAGS=—sysroot=$SR CPP="$BR&quot;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<br />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&quot;ar -DCMAKE_BUILD_TYPE=Release -DCMAKE_C_COMPILER="$BR&quot;gcc -DCMAKE_C_FLAGS=—sysroot=$SR -DCMAKE_INSTALL_PREFIX=$SR/usr -DCMAKE_LINKER="$BR&quot;ld -DCMAKE_NM="$BR&quot;nm -DCMAKE_OBJCOPY="$BR&quot;objcopy -DCMAKE_OBJDUMP="$BR&quot;objdump -DCMAKE_RANLIB="$BR&quot;ranlib -DCMAKE_STRIP="$BR&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 ../

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
#define ushort uint16
#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:

&quot;$BR&amp;quot;objdump <s>p libqsqlmysql.so | grep NEEDED<code>
<br />To correctly create a mariadb.so file instead of mariadb.so.1 edit libmariadb/CMakeLists.txt and comment out the block:<br />

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: