CrystaX NDK 10
This is a distribution of the CrystaX NDK, which has been developed as a drop-in replacement for Google's Android NDK (Native Development Kit). Compared to Google's NDK, the CrystaX NDK provides the same functionality as well as several great features and tons of fixes and improvements.
The main goal of the CrystaX NDK is to allow Android developers to produce standard conformant code and thus make Android native development more efficient. The CrystaX NDK dramatically decreases development time allowing usage of standard code working on multiple platforms (iOS, OS X, Windows, Linux, etc.) instead of distracting developers with Android's peculiarities and forcing coders to try to workaround them (or even write separate Android-specific implementations of functionality already implemented for another platform if a detected problem cannot be easily worked around).
Unfortunately, Android libc (Bionic) has very limited functionality (which differs from one Android version to another), so developers have been forced to take into account all its peculiarities, detecting in run-time which specific Android version the application is running on and applying specific workarounds. With CrystaX NDK, developers can forget about such problems, since CrystaX NDK provides complementary libcrystax, which is used to hide such differences between Android versions or even re-implement many of libc functions. Most importantly, with the help of libcrystax, the application behaves the same on all Android devices regardless of Android version.
Another goal of CrystaX NDK is to make some great features available for the Android native world. For example, support of Objective-C and another programming languages.
This project was initially started as a personal project of Dmitry Moskalchuk with the intention to just add missing C++ support (C++ exceptions, RTTI, and the Standard C++ Library) to the Google's Android NDK, but with time, many additional needs were discovered, and it turned out that improving the CrystaX NDK step-by-step was in fact the best way to force an evolution of native Android development. Since its beginning in 2009, numerous open-source and commercial projects have used the CrystaX NDK for porting and development for Android with minimal effort.
Nowadays, CrystaX NDK offers numerous great features, making native development for Android easier. See below the key features of the CrystaX NDK.
- Full support of wide characters
Wide characters are part of C and C++ languages and their standard libraries. For example, the C standard library provides functions allowing work with wide strings such as wcsnlen, wcsncasecmp, wcsncmp and others; the C++ standard library provides wchar_t specializations of standard C++ classes such as std::basic_string, std::basic_ostream, std::basic_regex etc. Unfortunately, Android libc (Bionic) either doesn't support wide characters at all or supports them in a very limited manner, depending on Android version.
With the CrystaX NDK, you get fully standard-compliant wide characters support, including multibyte-to-wide and vice versa conversions. You can easily port existing code or write new code that uses wide characters, strings, streams, and regular expressions not distracting on Android's peculiarities.
- Full support of C locales
Android libc (Bionic) has no native support of locales, so the only way to use localized input/output in native code is to implement localization in Java and refer to it through JNI. Obviously, such an approach adds significant run-time overhead, but it's the only choice if you're using Google's Android NDK.
Now, with CrystaX NDK, locales are supported natively, so just set a locale with standard setlocale and all further C standard function calls will use that locale for input and output. CrystaX NDK also supports so-called "extended locales" (part of IEEE Std 1003.1, 2013 Edition), providing companion locale-enabled functions for many standard C interfaces, such as printf_l, strftime_l, strfmon_l and others.
- Full math support, including complex and type-generic math functions
ISO C standard defines headers <tgmath.h> and <complex.h>. In Google's Android NDK, <complex.h> appears only starting from r10 and only for applications targeting Android 5.0 (android-21 platform), whereas type-generic math functions are not supported at all.
With CrystaX NDK, you get fully working complex and type-generic math regardless of the target Android version. Nothing more to say - just use it as defined in ISO C standard and enjoy!
- The most recent toolchains
The CrystaX NDK includes the most recent versions of GCC and Clang compilers. This allows developers to use new language abilities, such as new C++11/C++14 features. All compilers are built with high- and low-level optimizations, which enable generation of the most efficient code for target hardware.
- C++11/C++14 support
- Full C++ standard library
In addition, the CrystaX NDK offers a fully working C++11 standard library, including classes std::thread and std::mutex, functions/classes from std::chrono, and functions std::stol, std::stoul etc. These classes and functions are not available (or available with restrictions) in the Google's Android NDK because of a lack of functionality in Android libc (Bionic).
In the CrystaX NDK, we've taken care of the completeness of the C++ standard library and have fixed all such issues, so the full C++ standard library is available no matter which implementation you're using - GNU libstdc++ or LLVM libc++.
By the way, LLVM libc++ in CrystaX NDK is a first-class citizen, the same as GNU libstdc++, so you're free to use either one of them, your choice. By default, GNU libstdc++ is used.
- Boost C++ libraries out of the box
We provide prebuilt Boost C++ libraries (as well as header-only libraries) out of the box. Boost usage become as simple as can be. No need to build Boost libraries on your own anymore; no need to figure out what's wrong when it fails. Most important, Boost C++ libraries works much better with CrystaX NDK than the same libraries built by Google's NDK - because in CrystaX NDK they works on top of the much more standard-conformant base (yes, it's libcrystax, core of the CrystaX NDK).
Here you can see an example of how to start using Boost C++ libraries in your Android project.
- Objective-C and Objective-C++ support
The only languages Google's NDK supports are C and C++. CrystaX NDK adds support of Objective-C and Objective-C++ in addition to C and C++.
Starting from CrystaX NDK 10.2.0, we've added support of Objective-C v2 runtime and initial frameworks (Foundation and CoreFoundation).
Here you can see a simple example of how to use Objective-C for Android development. In two words, just add source files with the extension .m (Objective-C) or .mm (Objective-C++), specify them in LOCAL_SRC_FILES in Android.mk and add "APP_OBJC := cocotron" in Application.mk.
- Tons of fixes and improvements of standard C library implementation
It's a well-known fact that Android libc (Bionic) has many bugs in its implementation of standard C functions. For example, one of the most notorious bugs is strtod implementation, which works properly only for the simplest input string formats and fails for others required by ISO C Standard. Some of these bugs are fixed over time, others aren't. Anyway, even if some bugs are fixed, such fixes don't affect previously released Android versions, so developers are forced to live with them or implement their own workarounds. This significantly increases time for development or porting of native Android applications.
In CrystaX NDK, we've implemented our own versions of such buggy functions in libcrystax and have done so without altering the typical development work flow. Compilers/linkers use libcrystax transparently for developers so one won't even know that a libcrystax implementation is being used instead of a Bionic (except for the fact that the behaviour has been fixed). Also, using CrystaX NDK, you'll never run into a situation where a bug fix is available only for specific Android versions. When we fix anything in libcrystax, we ensure it works on all Android versions.
- To be continued...
We have plans for the further evolution of CrystaX NDK. We want to make it a comprehensive toolkit for native Android development, providing a solid basis for any POSIX-conforming software to be able run on Android without significant rewriting. To do that, we're asking for help from the community.
We've started a fundraising campaign on BountySource to continue the development of CrystaX NDK and keep it available free to all Android developers. We're asking everyone interested in the further evolution of native development for Android to help us. We would very much appreciate any kind of help - whether it is funding, contributions to the project by sending us patches, or helping to spread the news all over the world.
Please read more about CrystaX NDK’s history and our plans - and help us do that.
The content of the CrystaX NDK is covered by various open-source licenses. See the copyright disclaimers in each respective file for details.
Note that the CrystaX NDK release packages also contain prebuilt binaries for the compiler, linker, archiver, etc. The source codes for the toolchains are available at GitHub (you can use the build script to download it automatically).
The prebuilt GCC and companion binaries (GDB, binutils etc) are covered by either the GNU General Public License (GPL) or the GNU Lesser General Public License (LGPL). For details, see the files COPYING and COPYING.LIB under $NDK/toolchains/<toolchain>/prebuilt/<system>.
The prebuilt LLVM/Clang toolchains are covered by the LLVM "BSD" license.
Basically, licensing rules are the same as for Google's Android NDK - i.e., both commercial and non-commercial usage allowed. The only additions are regarding CrystaX parts, which are covered by a permissive BSD 2-clause license.
How to build
You can also build the distribution from sources if you don't want to use the prebuilt versions for some reason. Follow the instructions below.
Setting up the build environment:
Follow the instructions from the AOSP site (except the Java part):
WARNING!!! Building the Windows version of CrystaX NDK is only supported on a Linux host (cross-build used). Building on a Windows host is not tested and not supported.
Download the build script and run it.
\curl -sSL https://www.crystax.net/download/ndk-crystax-r10-build.sh | /bin/bashIt will take a long time - up to many hours. When the script is finished, it will print the directory containing the package with the NDK release.
- You're done! Use this package as a drop-in replacement for Google's NDK!