I'm new to the Android NDK. I want to know what is the benefit of native code in Android. How does it improve performance, and where is it (native code) used in Android?
-
1developer.android.com/sdk/ndk/index.html#overview– Jean HominalJun 18, 2010 at 9:57
-
developer.android.com/training/articles/…. See this quote "Native code is primarily useful when you have an existing native codebase that you want to port to Android, not for "speeding up" parts of your Android app written with the Java language."– RoelMar 24, 2016 at 16:13
2 Answers
The NDK allows you to write code using C/C++ and then link it into your Java application. You can potentially increase the speed of your application. However, it may be worth reading about Replica Island, as they don't use the NDK, however achieve very fast frame rates.
The downsides to the NDK are, it only compiles to specific CPUs (whereas staying in Java land means it will work on any targetted version of Android).
-
-
2
-
-
"Donal" i am trying to run ndk example on eclipse and following this link "mobilepearls.com/labs/ndk-builder-in-eclipse" but when i am trying to set refresh tab property ,,on that place i didn't get lib folder . when i try to run my application ,, getting "java.lang.UnsatisfiedLinkError: Library helloneon not found" exception,,,,,, please guide me what is the problem....– AndyJun 19, 2010 at 6:10
-
1@Maximus, the NDK supports two processors currently. The two supported devices are: * ARMv5TE (including Thumb-1 instructions) * ARMv7-A (including Thumb-2 and VFPv3-D16 instructions, with optional support for NEON/VFPv3-D32 instructions) (In the future it will support x86 too!) Jun 24, 2010 at 8:56
Droid, You can use native code, to optimize your application for speed. Especially when bit/byte operations are used in your code, like when you need to do compression / decompression of image files etc.
Native C code would use the underlying operating system's (linux) APIs (system calls), and hence would be much faster than when java code would have to be interpreted through the JVM.
Besides, allocation of large memory (to the tune of 25-30MB even!) can be done using native C code, using malloc(). This would not be possible when coding through java, in the confines of the application.
Most games use the native C code libraries for 2D / 3d graphics, input, sound etc...
If you are just beginning with the NDK, check out the following link for an easy tutorial with screenshots: http://mindtherobot.com/blog/452/android-beginners-ndk-setup-step-by-step/