20

I am about to start android application development.

From What is NDK? documentation I was not able to extract the following information:

Does using NDK actually introduce new features comparing to SDK?

I am interested in this because using NDK greatly increases application complexity, so if I am not interested in performance increase, are there other reasons to go for NDK?

What I mean is for example:

-restart phone

  • (I know neither SDK nor NDK allows this, I just use it as an example of what I mean) let's say java SDK does not allow this, but some native libraries do - then the answer to my question would be yes, NDK does add some functionality

Thanks in advance for any helpful answers.

Ninad Kulkarni
  • 61
  • 1
  • 11
hendrix
  • 3,364
  • 8
  • 31
  • 46

5 Answers5

17

You really should use SDK, unless you have a good reason to use NDK. Good reasons may vary, but for example, you could use NDK:

  • If you want to use OpenGL ES 2.0 for Android 2.1 (Eclair), it is only avaiable through NDK. The SDK support for OpenGL ES 2.0 began with the Froyo version.

  • If you want to use Renderscript

  • If you have a great portion of your app's logic written in C/C++

Alesqui
  • 6,417
  • 5
  • 39
  • 43
15

The NDK is much more limited in terms of functionality.

What you do get from the NDK is the ability to write your app in C++ and compile it to native ARM code. If you like C++ better than Java, if you have an existing C++ app that you want to port to Android, or if you just need the extra performance that only native code can offer, then by all means you should use the NDK.

I haven't done this myself, but another alternative is to write hybrid app, where the app is written mostly in Java, with selected functions written in C++ that are called from the Java code.

Alex Bitek
  • 6,529
  • 5
  • 47
  • 77
Miguel Grinberg
  • 65,299
  • 14
  • 133
  • 152
  • 4
    Sorry for commenting so late into this question, but I just wanted to make sure it is clear that writing in C++ because you prefer it is NOT a good reason to use NDK. –  Jun 05 '13 at 21:59
  • 1
    @DealerNextDoor Because no one should prefer C++, or because no one should want to use the NDK? – CorayThan Mar 01 '14 at 10:43
  • 2
    @CorayThan Neither; writing in C++ purely because you don't want to write in Java is a bad reason. As stated on the NDK download page, "Before downloading the NDK, you should understand that the NDK will not benefit most apps. As a developer, you need to balance its benefits against its drawbacks. Notably, using native code on Android generally does not result in a noticable performance improvement, but it always increases your app complexity. In general, you should only use the NDK if it is essential to your app—never because you simply prefer to program in C/C++." –  Mar 03 '14 at 00:50
  • @CorayThan what if you only know c++? – Alex_Nabu Dec 09 '14 at 14:49
  • 1
    @Alex_Nabu Don't write Android, or learn a new language? – CorayThan Dec 09 '14 at 17:27
  • 1
    @CorayThan I'm in earnest. Would you seriously recommend spending months learning a new language as opposed to using the NDK? Surely the disadvantages aren't that bad. – Alex_Nabu Dec 09 '14 at 19:34
  • @Alex_Nabu Would depend on the situation. If you want to write a quick little app by yourself, sure, use C++. Otherwise, you should learn java and do it the right way. (Or use phone gap and javascript ...) If you know C++ well, writing an android app in Java shouldn't take "months" of extra time. And to be honest, I think every programmer should know more than one language. – CorayThan Dec 11 '14 at 19:48
  • @Alex_Nabu Because even if you already know C++, learning java to build an app is still easier and simpler, particularly when the platform already runs on a vm. – user27886 Jan 28 '15 at 02:17
  • NDK is not limited to "ARM" as mentioned in answer, it depends on target platform, x86 as well. – rkosegi Jul 02 '15 at 12:04
10

The only reasons to use the NDK as far as I know is to squeeze extra performance out of your application and get closer to the bare metal. If you don't need to do either of these things, you should probably stay away from the NDK.

Also note that the Dalvik VM already has some pretty awesome performance and comparatively simpler.

Alex Bitek
  • 6,529
  • 5
  • 47
  • 77
Kurtis Nusbaum
  • 30,445
  • 13
  • 78
  • 102
9

For me, I think it’s important to know the NDK which is a powerful tool in the development of mobile applications. Especially if you want to develop a multiplatform application, the NDK is unbeatable in this domain. Since the same code written in C + + for Android can be easily ported and run the same way on the iOS, Windows or any other platform without changing the original code. Which actually save a lot of time in the development of applications which are developed for being run on multiple platforms; as games and other classic applications. Thing you cannot do with the SDK.

Valynk
  • 466
  • 7
  • 7
  • 1
    Agree. Nowadays it's hard to imagine any good app would like to get stuck with only one platform like Android. So the general practice is to leave everything beyond UI layer to native code so that they can be easily ported to other platforms, some of which might be manufacturer specified ones. – Kun Wu Mar 27 '15 at 07:27
2

Native methods are platform-specific code. They are usually written in languages such as C or C++ and contained in libraries(dll's). It is possible to create a hybrid Java application that benefits from such libraries.

Reasons for Using Native Methods

  1. Gaining access to special capabilities of your device or or Android OS
  2. Gaining extra speed
  3. Gaining access to a large body of existing legacy code

Typically, good use cases for the NDK are CPU-intensive applications such as game engines, signal processing, and physics simulation

The major disadvantage of native methods is that you won't have cross-platform capability.

Now if you don't know what native code is, then probably you don't need to use native code. Android NDK documentation explains this well:

..., you should understand that the NDK will not benefit most apps. As a developer, you need to balance its benefits against its drawbacks. Notably, using native code on Android generally does not result in a noticable performance improvement, but it always increases your app complexity. In general, you should only use the NDK if it is essential to your app—never because you simply prefer to program in C/C++. When examining whether or not you should develop in native code, think about your requirements and see if the Android framework APIs provide the functionality that you need.

Caner
  • 57,267
  • 35
  • 174
  • 180