Java – How useful is JNI in android

androidccompile-timejavaperformance

In java/android we can call code written in the c/c++ language for execution speed advantage. I have heard of Ahead Of Time compilation which (as far as i know) compiles the entire application to native code during its installation.

I want to perform some mathematical operations like compression, encryption (not images, audio or video processing) to compare computational power of devices and whose code can be written in both java as well as c/c++.

My doubt is: since all the java code is converted to native in android is there any use of JNI/NDK and what is it?

Update1:
Here it is mentioned:

Unlike Dalvik, ART introduces the use of ahead-of-time (AOT) compilation by compiling entire applications into native machine code upon their installation.

Consider i have an encryption algorithm (which does not use any language specific constructs like pointers). Which normally when compiled to native code (c/cpp) will give maximum execution speed. But as quoted, if all the code is compiled into native upon installation of app is there any difference of performance(speed) between the encryption method(written in java) and (same)encryption funtion (in cpp).

I want to know best approach for implementing encryption algorithm in android or similar vm based os.

Best Answer

Assume it is not just an Android application. Assume your company needs applications for Android, iOS, Windows, MacOS and Linux. And there is shared functionality. Which is written in a language available on all platforms, that is C++.

You now have the choice of re-writing a huge part of your application in Java (and Objective-C or Swift, and C#, and whatever is the fashion in Linux), which will be very expensive and a maintenance nightmare, or using the C++ code using JNI.

Related Topic