Benefits of using Native in Android

So I am beginning a semester long project and my group has decided to use Android as the target platform. This spiked my curiosity on a question in particular.

I'd imagine under the large majority of the development cases Java and the virtual machine are the best paradigm to be developing under. My question is: What circumstances warrant using the native software development kit (C/C++) as opposed to Java?

According to Android documentation there are a few points to keep in mind:

  • "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++."

  • "Typical good candidates for the NDK are self-contained, CPU-intensive operations that don't allocate much memory, such as signal processing, physics simulation, and so on."

  • That is a VERY broad set of statements (especially that last one). From what I have read, using most JVMs nowadays the speed of execution of byte code via JIT compiling is almost, or just as quick as compiling directly to machine code. So I'm looking for multiple responses that clarify in a deeper sense, and more specifically when do we decide to use native languages for Android development, and what are some good examples of those situations?


    From Intel Developer Zone, NDK Android* Application Porting Methodologies , Performance Implications and the Cost of JNI

    Specifically, using native code in an Android* application doesn't guarantee a performance boost! Commonly, performance gains can be appreciated in cases such as when the native code involves CPU-centric operations (such as heavy – duty usage of SSE instructions ), but at other times, when for example, the application at hand is simply providing a complex web interface to the user, the use of native code through JNI may hinder performance. There is no "written rule" as to when the NDK should and shouldn't be used...

    SSE is an extension of the original MMX instructions set introduced for complex arithmetic processes with precision such as 3D rendering, games, image processing, voice and handwriting recognition, scientific computations... etc so NDK should be useful in this cases.

    NDK supports the following instruction sets

  • ARMv5TE, including Thumb-1 instructions
  • ARMv7-A, including Thumb-2 and VFPv3-D16 instructions, with optional support for NEON /VFPv3-D32 instructions
  • x86 instructions
  • MIPS instructions
  • NEON technology support is interesting and leads to the same conclusion:

    can accelerate multimedia and signal processing algorithms such as video encode/decode, 2D/3D graphics, gaming, audio and speech processing, image processing, telephony, and sound synthesis by at least 3x the performance of ARMv5 and at least 2x the performance of ARMv6 SIMD.


    As everyone says, native Android programming is suggested when you need a performance boost on your app. But I think there may be another reason to use NDK: Multiplatform code.

    It sounds crazy, and it is. When you use to program with many platform targets (and you don't use frameworks like Xamarin, Corona SDK, Appcelerator and other ones), commonly you have to re-write most of the controller and view code for each platform, not a very smart way.

    But, almost all of the controller code could be ported using standar C/C++ because, (irony!) all mobile platforms supports standar C/C++, so you can write the logics to some libXXX and re-use it in all your target platforms WITHOUT losing a lot of performance (like Appcelerator or Cordova).

    That's my opinion.

    链接地址: http://www.djcxy.com/p/76952.html

    上一篇: GCC宏扩展来调用另一个宏

    下一篇: 在Android中使用Native的好处