How to create a Java JNI dynamic-link library for ANDROID,MAC and Windows platforms

Source: Internet
Author: User

Java Native Interface (JNI) is a bridge between Java and C/s + +. In some cases, to improve the performance of Java programs and extend the functionality of Java programs, we need to use JNI. For example, when we download a JDBC jar package, we can see the dynamic link library containing the different platforms in the database:

This article describes how to create one of the simplest JNI dynamic link libraries for the ANDROID,MAC and Windows platforms.

Reference article:

Getting Started with JNI on Android, Windows and MacAndroid

Download the NDK and configure the path in eclipse:

Create an Android engineering Hellojni. Right-click the project, select Add Native support to automatically generate C + + projects:

Modify the C + + code to configure ANDROID.MK:

Clicking Save will automatically generate the dynamic link library You can also manually generate by command ndk-build :


Open Visual Studio and create a Win32 project Hellojni:

Select the DLL in the app type:

To configure the path of the header files and libraries:

Click Build to generate Hellojni.dll:

Mac OS X

Open Xcode and create a project hellojni :

Framework Selection STL:

In the build settings, configure the JAVAVM header file path and the library path:

Click Build to generate libhellojni.dylib:

How to use JNI in Java Engineering:

Declaration Native Interface:

Public native String Stringfromjni ();p ublic native static void Nativeprint ();

To load a dynamic-link library:

static {system.loadlibrary ("Hellojni");}

git clone

How to create a Java JNI dynamic-link library for ANDROID,MAC and Windows platforms

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.