If you are still focusing on Windows desktop development, it is time to migrate to IoT and mobile technologies that have a big boost in the near future. In this post, let’s take a glimpse of how to build C/C++ “hello world” program for Raspberry Pi and Android on Windows using GNU toolchain and NDK.
Java Native Interface (JNI) is the glue between Java and native code such as C, C++, and assembly. With JNI, Java applications are capable of supporting platform-specific features. JNI enables developers to call low-level APIs (e.g. SQL, OpenGL etc.) to make Java application more powerful with higher performance. For example, we can download a JDBC driver, and unzip the jar package to take an insight. The driver is not written in pure Java. It also contains native libraries for Linux, Mac, and Windows.
Since JNI is so useful, I’d like to share how to get started with JNI on Android, Windows, and Mac.
JNI on Android
Download NDK and configure the location in Eclipse:
Create a new project named hellojni. To automatically generate the native C/C++ code and configuration file, you just need to right-click on your project and select Add Native Support:
After that, a JNI project will be automatically generated. To build the shared library, you just need to implement JNI methods in C/C++, and add configurations in Android.mk.
JNI on Windows
Create a Win32 project named hellojni in Visual Studio: