Build Qt 5 MySQL Plugin for Android

From Qt Wiki
Revision as of 14:06, 14 January 2015 by Maintenance script (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

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:

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.

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:

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:

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:

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:

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:

Now you’re ready to compile and 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:

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

Compiling mysqlclient (Option 2)

Stub for someone to experiment with and update this page

Compiling the Qt mysql plugin

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: