By Sibers Android Team Leader Sergey Kiryukhin
If you want to develop an Android application, chances are you will be advised to use NDK. So, what exactly is this modern tool, and why so many developers recommend it? This article will answer these questions, as well as explain the differences between using NDK and Java. You will gain a clear understanding of the advantages and disadvantages of NDK, as well as for what purposes NDK is recommended and for what purposes it is not recommended.
NDK (Native Development Kit) is a type of technology that is used to develop Android app components by using so-called “native language”. In many cases, Android applications that are written in Java have low productivity. When developing using Java, you will be able to use just 24 Mb of RAM, whereas developing with NDK will give you more than 24 Mb, thus increasing efficiency. In addition, by using NDK you will also have a greater increment of process execution speed.
Another handy feature of NDK is the option to use many native libraries. Since you can use various ready solutions for your project (e.g., a library which completes math tasks), the overall time for development decreases.
You must be aware of the fact that NDK cannot be the sole technology for development. You will have to use another platform as well due to some of the disadvantages of NDK. For example, NDK makes it impossible to work with events (keyboard, touchscreen or accelerometer) and sounds. For these tasks you should use Java because NDK native libraries can be easily implanted into Java shell.
NDK Advantages
NDK is especially good for tasks when process acceleration is needed, for example, as part of game development where you calculate a game physics engine or AI. These calculations require a lot of RAM despite the fact that the gameplay background itself may require only 3 Mb. Java copes with this work with difficulty, so the majority of games today are developed with NDK (“Angry Birds” for Android is a great example of a program developed with NDK). Sibers developers not only actively use NDK-tools, but also organize workshops based upon this technology for colleagues and interns. This article is a result of one such workshop.
More examples of beneficial usage of NDK include tasks regarding pattern recognition, data encryption and compression, images/video/audio processing, and all actual and modern trends which require a good deal of complicated calculations. It would be quite simple for a PC to perform these tasks, however mobile platforms have limited resources. In fact, Android is a more “convenient” development platform than the iPhone. The iPhone has many limits for potentially dangerous actions (e.g., access to user’s sms, emails, address book, wi-fi signal strength information etc). Thus these dangerous actions could never be legally realized on an iPhone application that needs to be approved by the iTunes App Store. The Android market does not restrict the usage of these actions.
Another nice and important advantage of NDK is the compatibility it has with OpenGL ES 2.X. This technology allows for the creation of more beautiful 3D graphics.
Disadvantages
While NDK improves efficiency in many cases, there are also situations when NDK works like Java, but requires even more development resources than Java. Take, for example, the development of an application with simple calculations and a lot of supplemental information to be displayed using a complicated user interface. Classic examples of this type of application are guide-books and shopping apps. In these cases using Java would be more beneficial, due to its effective tools for easy interface development. “Easy development” means that you save both money and time for your clients.
Interaction with Other Platforms
The use of native language makes porting applications easy, because NDK makes it possible to implement standard native code libraries. These libraries can be used for other iOS platforms development; however they do not simplify porting to Windows Phone 7, Blackberry, or Symbian. You will need to rewrite most of the code in these cases.
Porting C++ desktop apps to Android becomes simpler with NDK, but it does not mean that you can replace the app without any changes. This would be too complicated, slow, and inappropriate for a small screen.
To Sum Up…
You have now seen how the use of NDK helps solve many of the problems with Java, however development with this tool is not always ideal.
NDK should be used for:
- Developing components with complicated calculations (game physics, AI, pattern recognitions, data encryption and compression, images/video/audio processing);
- Making “a clone” of a C++ desktop application for Android.
NDK should not be used for:
- Creating user interfaces;
- Working with bulks of static data.
This article is weird.
w23, why do you think so?
[…] Первым из серии был семинар Android Senior Developer’а Сергея К. Семинар был посвящен использованию Native Development Kit (NDK), который позволяет применять нативные языки при разработке приложений для Android. Сергей рассказал коллегам про особенности использования этого инструмента, очертил круг задач, для которых применение NDK будет оптимально и скорость выполнения процессов действительно увеличится. Подробнее об NDK вы можете прочитать в нашем англоязычном блоге. […]
I read this piece of writing completely concerning the resemblance of
most recent and previous technologies, it’s awesome article.