Building Qt for android on Mac OSX using the crystax NDK
-
Hi all,
We are porting our Qt Windows/MacOSX/iOS app to android. We have a huge codebase using boost serialization. Boost serialization relies on wide chars, which are not supported by then official NDK. So our plan is to build Qt against the crystax NDK. Anyone succeeded on building Qt 5 against the crystax NDK?
So far, we have configured Qt 5.4 beta sources to start compiling, using the following configure options:
@../qt-everywhere-opensource-src-5.4.0-beta/configure -xplatform android-g++ -nomake tests -nomake examples -android-ndk /Users/ro/lib/ANDROID/adt-bundle-mac-x86_64-20140702/android-ndk-r8-crystax-1/ -android-sdk /Users/ro/lib/ANDROID/adt-bundle-mac-x86_64-20140702/sdk/ -android-ndk-host darwin-x86_64 -android-toolchain-version 4.7 -android-ndk-platform android-9 -skip qttranslations -skip qtwebkit -skip qtserialport -skip qtwebkit-examples -no-warnings-are-errors -L /Users/ro/lib/ANDROID/adt-bundle-mac-x86_64-20140702/android-ndk-r8-crystax-1/sources/crystax/libs/armeabi-v7a -I /Users/ro/lib/ANDROID/adt-bundle-mac-x86_64-20140702/android-ndk-r8-crystax-1/sources/crystax/include -v@
And it starts compiling, but fails trying to compile the file qtextcodec.cpp, with the following error:
@In file included from /Users/ro/lib/QT/qt-everywhere-opensource-src-5.4.0-beta/qtbase/src/corelib/codecs/qtextcodec.cpp:34:
In file included from /Users/ro/lib/QT/qt-everywhere-opensource-src-5.4.0-beta/qtbase/mkspecs/macx-clang/qplatformdefs.h:34:
In file included from /Users/ro/lib/QT/qt-everywhere-opensource-src-5.4.0-beta/qtbase/mkspecs/macx-clang/../common/mac/qplatformdefs.h:61:
In file included from /Applications/Xcode5.1.1/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr/include/sys/shm.h:84:
/Applications/Xcode5.1.1/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr/include/sys/_types/_pid_t.h:30:9: error: unknown type
name '__darwin_pid_t'
typedef __darwin_pid_t pid_t; @We are using Mac OSX 10.9.5.
Anyone?
Thanks,
Robert. -
Hi Robert,
Obviously, Qt's configure script uses host's includes instead of NDK's - something goes wrong and Qt's configure script didn't patched proper include path.
Probably the best way to compile Qt with CrystaX NDK would be to a) create so called 'standalone' toolchain and b) follow usual Qt cross-build procedure with that standalone toolchain.To make standalone toolchain, just cd to /Users/ro/lib/ANDROID/adt-bundle-mac-x86_64-20140702/android-ndk-r8-crystax-1 and run the following command in terminal:
./build/tools/make-standalone-toolchain.sh --toolchain=arm-linux-androideabi-4.7 --system=darwin-x86_64 --install-dir=$HOME/arm-linux-androideabi-4.7This will create 'traditional' cross-toolchain containing all required for building for target Android - compiler, linker, tools and sysroot (both headers and libraries). I don't know Qt deeply, but I suppose it would be easier to build it with standalone toolchain.
-
Hi,
thanks for your reply.
Unfortunately, I get exactly the same error after following the steps you suggested. -
Hi,
I finally got Qt for android compiled agains the crystax NDK. I did modify the qmake.conf file, adding the missing include and lib paths from the crystax NDK.I have now a problem with the deployment. Although I have used the -lgnustl_static option in the QMAKE_LIBS_PRIVATE in the qmake.conf file, the deployment process is copying libgnustl_shared.so to the output lib directory.
Is there any way to tell the deployment process to not to copy the libgnustl_shared.so file to the output lib directory?
Thanks.
-
Hmm, it's not clear what is "deployment process" you stated above. Is it Qt's deployment scripts or smth from NDK itself? Could you describe it a bit more detailed?
-
Yeah, sure.
I mean the process that takes place when in Qt creator you select Build -> Deploy All. In principle, nothing to do with the NDK you chose.During this process, all the needed qt shared ".so" files are copied to the output lib directory. One of these files is libgnustl_shared.so, but the qmake.conf file has the option -lgnust_static (not shared). My question is: Why? and, How could I change that behavior?
-
@crystax Hello, here I am again with a similar issue.
I'm trying to build Qt (5.6.0-RC) using the last version of your Crystax NDK (10.3.1). My configure command line looks like this:./qt-everywhere-opensource-src-5.6.0-rc/configure -xplatform android-g++ -nomake tests -nomake examples -android-ndk /Users/ro/lib/ANDROID/crystax-ndk-10.3.1/ -android-sdk /Users/ro/lib/ANDROID/android-sdk-macosx/ -android-ndk-host darwin-x86_64 -android-toolchain-version 4.9 -skip qttranslations -skip qtserialport -no-warnings-are-errors -prefix /Users/ro/lib/QT/Qt5.6.0-rc-android-crystax -android-ndk-platform android-19 -v
meaning that I'm using the crystax NDK 10.3.1, my Mac as the host compiling Qt, the 4.9 NDK toolchain version, and the android-19 NDK platform version. Well, after changing QTDIR/qtbase/mkspecs/android-g++/qmake.conf by modifying these lines (Line 83):
ANDROID_SOURCES_CXX_STL_LIBDIR = $$NDK_ROOT/sources/cxx-stl/gnu-libstdc++/$$NDK_TOOLCHAIN_VERSION/libs/$$ANDROID_TARGET_ARCH $$NDK_ROOT/sources/crystax/libs/armeabi-v7a ANDROID_SOURCES_CXX_STL_INCDIR = $$NDK_ROOT/sources/cxx-stl/gnu-libstdc++/$$NDK_TOOLCHAIN_VERSION/include $$ANDROID_SOURCES_CXX_STL_LIBDIR/include $$NDK_ROOT/sources/cxx-stl/gnu-libstdc++/4.9/libs/armeabi-v7a/include
the configure script doesn't complain, and running make, it starts compiling. But I'm getting a compile error:
qthread_unix.cpp:559:49: error: 'PTHREAD_INHERIT_SCHED' was not declared in this scope pthread_attr_setinheritsched(&attr, PTHREAD_INHERIT_SCHED);
Having a look at the source file, that piece of code should only be compiling if QT_HAS_THREAD_PRIORITY_SCHEDULING is defined, which isn't true for ANDROID. That makes me think that probably the Crystax NDK (or toolchain, sorry, I'm a bit lost here) is not #defining ANDROID. A similar problem as described in this bug report: https://bugreports.qt.io/browse/QTBUG-41382. (So the compilation process doesn't know we are building for Android?)
Also it's worth mentioning that replacing the Crystax NDK by the current Google provided "android-ndk-r10e", the compilation is successful.
Any idea on how could I successfully compile Qt for Android using the Crystax SDK?
Thanks,
Robert.