Android development
Raiting:
3

Improved Android NDK (Native Development Kit)


I am engaged in developmental work for Android for some time, and I gradually came to the conclusion that I have been lacking many things as a developer. At the beginning of 2010, I lacked only C++ exceptions and RTTI. Without them, any non-trivial C++ code could not be ported to Android, and it required almost complete rewriting. It was a very important limitation, which worried me a lot. Fortunately, Android is an open source, so I started working on that, keeping in mind old saying (if you need something, do it yourself). I got surprised, because to make support for C++ with exceptions and RTTI turned out pretty easy. It only took about a week of work. Then the website was made on which were posted the NDKs for Windows, Linux and Mac OS X, as well as a patch and the instructions for assembly.

The problem was urgent, so the project was very popular. During the first month I received many letters with the questions, requests for additional functionality and simple thanks. One of the most frequently asked question was: “Will Google include these changes to the mainline?”. I honestly replied that I do not know, but there is hope, because David Turner (system architect of Android) is very interested in my patches, and he promised to pay attention to them.

It took about a year before the Corporation included to the mainline my patches. During this time Google has released two releases (r3 and r4), and I have adapted them as r2. I continued to post improved NDKs with patches and installation instructions on my website. Thereby, within that time were gathered a large audience of users who needed them. Many Open Source and commercial projects have been able to port their code to Android using my NDK. Among them are Open Source, OpenCV and Ogre3D.

Finally, when NDK r5 was released, Google has integrated my patches in the mainline. It would seem that here is the end of the project, but by that time there were accumulated quite a few other questions to the NDK. The project still required some additional improvements, so I decided to continue the project and I redirected Android NDK + full C++ to Improved Android NDK, as I was convinced by experience that the best way to achieve these changes in the mainline. A specific list of improvements is constantly updated, and it can be seen on my website on a page of the specific release.

So, here I will describe in consecutive order the main improvements in CrystaX NDK, distinguishing it from Google NDK.

Supporting the wide characters


I do not know why, but in Google NDK was committed sabotage, namely wchar_t has been made in the size of 1 byte. The explanations that I got from David Turner did not satisfy me. He insisted on the fact that the code, which uses wchar_t usually, it is non-portable, so you need to use UTF-8 that is stored in the regular char strings. I did not mind using UTF-8, but I pointed out to him that the non-portable code with wchar_t does such solutions as in Google NDK. I guess, nothing came out of it, each of us kept his own opinion, but I figured that it is required to support the wide characters / strings / streams.

I began to develop the support for wchar_t in the Standard C library and Std C locales basing on the code from FreeBSD. The task was difficult and took a few months before I got a stable implementation. Unfortunately, it is still not complete (there has not been completed support for all locales yet, only UTF-8 is supported), but in practice it is more than enough for many projects. I myself was involved in projects where wide characters / strings / streams were actively used, as well as I know that from the letters of users who have benefited from my implementation.

C++11


When a new international standard C++ was released, I wanted to use the new language features and standard library. Unfortunately, Google NDK is based on GCC 4.4.3, which although includes some features of C++0x, though it is out of date. Therefore, it was decided to add a new one that is based on GCC 4.6.3 toolchain in CrystaX NDK. At the moment CrystaX NDK contains two versions of the compiler - 4.4.3 (as in Google) and 4.6.3 (new one). Switching between them is very simple, please type in Application.mk of your project:
APP_TOOLCHAIN_VERSION: = 4.6.3

Please note that this is not enough to take advantage of C++0x. In order to enable C++0x you must type (also in Application.mk):
APP_USE_CPP0X: = true

Graphite optimization framework


GCC 4.6.3 is compiled with support for Graphite optimization framework in CrystaX NDK. Here is a link to GCC Wiki.

Objective-C


Google NDK supports only C and C++ for the native development. This is not bad, but at some point it was discovered that there is a lot of code that was originally written for iOS in Objective-C, which now must be ported to Android. Certainly, you can use the traditional way and rewrite it from scratch, but also you can add the support of Objective-C in Android. I came to the conclusion that it is better to have some possibility than none, and I proceeded to implement this idea. At the moment, there are ported Objective-C compiler and basic GNU Objective-C library. Also, I plan to port GNUStep to Android (then it will be possible to transfer Cocoa code with minimal changes), but the task is rather big, and it obviously will take some time. Anyway, you can start using Objective-C on Android now – you just add LOCAL_SRC_FILES source code with the extensions .m (Objective-C) or .mm (Objective-C++).

Static code analysis


I am a little paranoid like many developers. I'm never sure for 100% in my code, because I came across stupid mistakes too often like mine and others. Therefore, I am following the main rule, "there are never too many code checks". There are quite a few different code analyzers, but I decided to start with the Clang static code analyzer for Android. This project is actively being developed, and it analyzes quite well C and Objective-C code (unfortunately, it does not do C++). In order to use this feature first you must install Clang, then make sure that the script “scan-build” from the Clang package is available from the command line, and you run the Android build project:
ndk-build ANALYZE = 1

This command will bring Android project as usual, but also it will analyze it using the Clang analyzer, and if errors will be found, it will report about them in the end.

I plan to add support for other analyzers as well.

File system driver at the application level


This feature is not ready yet for full use and is under active development, but I still decided to mention about it, who knows, maybe it will save someone a week or months of work.
In an application that was built with the help of CrystaX NDK all calls IO API (such as open, read, write, etc.) are intercepted and analyzed. This is done to embed the so-called "drivers" - filters that could change writing / reading data for the application. For example, compressing or encrypting data. Please note that changing the application code is not required! You just need to type in the code at the start something like this:
mount("/path/to/storage", "/target", "compressed", 0, "GZIP")
Voila - all the data that is written to /target will be automatically compressed by gzip, and read data from /target will be automatically decompressed.

However, once again - this feature is not yet ready, but is in the final stages of development. It is quite possible within the next month it will stabilize. However, it is possible that someone may seem, it is suitable for use right now - well, I do not mind.

Conclusion


The more I engage in the Android platform, the more I get unmet needs. So far I have the time and effort to implement everything yourself, but obviously this cannot last forever. Therefore, I call to enthusiasts to participate in this project, let us do the Android platform such as we want to have it! Eventually, this is the main advantage of Android as compared to iOS and Blackberry. We can make this OS and tools as we need. Let us go ahead and do it!
xially 31 january 2012, 18:41
Vote for this post
Bring it to the Main Page
 

Comments

Leave a Reply

B
I
U
S
Help
Avaible tags
  • <b>...</b>highlighting important text on the page in bold
  • <i>..</i>highlighting important text on the page in italic
  • <u>...</u>allocated with tag <u> text shownas underlined
  • <s>...</s>allocated with tag <s> text shown as strikethrough
  • <sup>...</sup>, <sub>...</sub>text in the tag <sup> appears as a superscript, <sub> - subscript
  • <blockquote>...</blockquote>For  highlight citation, use the tag <blockquote>
  • <code lang="lang">...</code>highlighting the program code (supported by bash, cpp, cs, css, xml, html, java, javascript, lisp, lua, php, perl, python, ruby, sql, scala, text)
  • <a href="http://...">...</a>link, specify the desired Internet address in the href attribute
  • <img src="http://..." alt="text" />specify the full path of image in the src attribute