Friday, May 17, 2013

Qt 5 for Android (Fail in MinGW)

I am very interested in running Qt 5 on Android. Qt/QML is THE platform for developing awesome user interfaces in less time than it takes to eat a delicious grilled dinner. When Digia/Qt Open Source announced that it would target Android I fired up the grill. But I was disappointed; even though there is a wiki page that has full instructions on how to set up Qt Creator to build Android apps, there are a copious amount of steps to do the setup! Having fallen victim to these in the past (either they are out of date, don't give enough info, etc.)- I figured I would write about my experiences in following the easy steps online.

The easy steps are found at:

http://qt-project.org/wiki/Qt5ForAndroidBuilding

I will give you background about myself: I am familiar with C++ and have a great love for it. I don't know a thing about developing for mobile/embedded platforms. This will be a challenge for me as I'm unfamiliar with the technical mumbo jumbo. I guess this makes me the perfect guinea pig to do this installation. A word of note before beginning, please take note of the system you are on; in particular know whether you have a 64 bit system vs. 32 bit. I'm doing this installation on a 32-bit system. Let's start!

0) I'm adding a step 0. All of the steps use tools other than what you may already have. The list of tools I've found so far includes:

  • Perl: I used Active Perl v. 5.16.3, seems to work so far.
  • 7-Zip: Used this to unzip the NDK when you get it.
  • Git command line (when installing, make sure you add git to the DOS command line).
  • mingw compiler, with the compiler in the path.
  • The Java Development Kit (I'll talk more about this later).
After you are done installing all of these tools, make sure they all work on the command line. Open it up and try invoking each program (perl, git, and javac). 7-Zip can be used via a context menu (right click).

1) Android SDK. I downloaded this from http://developer.android.com/sdk/index.html. When I double clicked and installed I selected package 4.0 (that's what my ASUS Transformer can handle). This seemed easy enough so I'm still feeling good about this whole thing.

2) Android NDK. They say you have two options: use the official from Google or use the custom NDK provided in the link. Obviously they prefer the latter. http://code.google.com/p/mingw-and-ndk/downloads/list . This is where I get a little skiddish. There are a lot of choices you can make- so the best advice I can give is to try and match your platform the best you can. In my case, I chose android-ndk-r8e-ma-windows-x86.7z because I want the android NDK for Windows x86. It was the closest match.

3) Qt Creator 2.7.1. Now I didn't build this one- I downloaded the binary. http://qt-project.org/downloads/#qt-creator . 

4) I cloned Qt 5 using the instructions on the main site:

git clone git://gitorious.org/qt/qt5.git qt5
cd qt5
perl init-repository

Surprisingly, the last command is what seems to be taking forever. This will do a bunch of checkouts into your system using git. In fact, it's taking so long I'm going to go to sleep.

5) I attempted to perform a configure call using:

./configure -developer-build -xplatform android-g++ -nomake tests -nomake examples -android-ndk <path/to/ndk> -android-sdk <path/to/sdk> -android-ndk-host windows-x86 -skip qttranslations -skip qtwebkit -skip qtserialport -skip qtwebkit-examples

This didn't work because it did not understand the option "android-ndk-host". At this point, my confidence was shot. I knew the rest of the steps wouldn't work no matter what. There are two issues I have with this configure step: 1) android-ndk-host isn't a recognized flag (the biggest problem) and 2) Where is the documentation for android-ndk-host? Is the argument if you are windows win32-x86 or windows-x86 or does it require the compiler? Some consistency across the platform names would help make this a smoother build process but I digress.

After taking out the -android-ndk-host windows-x86, it seemed to start working. At the very least configuration "succeeded".I chalked it up to, "Maybe the Qt development team removed the android-ndk-host flag, maybe I'm going to be okay!" No.

6) To build this thing, I had to use mingw32-make. This is essentially a cross compilation build and the tools for mingw32 are fine. It uses one of the compilers in the ndk toolchain to actually do the build. The next problem I've run into is that this will not build with mingw32 on Windows- It fails with:

Cannot find -lQtCore5

A valid error. I searched through the directory and I did locate libQtCore5.so. When you get errors like this you know they are coming from some sort of build script error where it isn't putting the library in the correct place. Low and behold I got this error when running mingw32-make:

process_begin: CreateProcess(NULL, move, libQtCore.so.5.1 "..\..\lib ", ...) failed.

Instead of trying to troubleshoot the build scripts on a platform that is fighting me the entire way, I think I'm going to jump over to Linux. It looks like the build is much more "stable" there. Sorry if it sounds like I am complaining about the Qt build; but I think that these are all perfectly valid flaws in the build process. I think the biggest flaw is lack of documentation about what the variables in configure do. 

No comments:

Post a Comment