Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Benefits of using Native in Android [closed]

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?

like image 875
Brant Unger Avatar asked Jan 16 '14 15:01

Brant Unger


People also ask

What are the benefits of a native app?

Native apps are very fast and responsive because they are built for a specific operating system and are compiled using the platform's core programming language and APIs. As a result, the app is much more efficient. The device stores the app which allows the software to leverage the device's processing speed.

What are the disadvantages of native apps?

The disadvantage of native app development is that the code written for a mobile platform cannot be tailored for another platform. Also, maintaining native apps requires a lot of effort. Enhancements, security updates etc. cannot be simply loaded on to the server as compared with a web app.

Why native apps are better than cross-platform?

Native mobile development allows you to build apps for a particular operating system — either Android or iOS. Cross-platform mobile development, in contrast, allows you to build apps that target several operating systems.


1 Answers

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.

like image 101
vzamanillo Avatar answered Oct 27 '22 05:10

vzamanillo