Search code examples
androidandroid-studioandroid-ndkjava-native-interface

Android Studio Project for JNI library


I am writing a JNI library for Android, to be distributed and shared across several projects.

I found tutorials on creating an Android application that includes native code. I found tutorials on adding JNI libraries to an existing application.

However I did not find how to create a standalone JNI library on Android Studio. When creating a new project it automatically assumed I want to create an application, there is no option for creating a library.


Solution

  • Android Studio model is Project-centered, where a project is an application. You can have an empty application, but it may be useful to create a basic app that will help you test your native library.

    You can put all your native code in a separate Library module. Note that this will involve the Java wrapper, too. JNI library for Android is useless without a Java wrapper, even if it only declares the native methods and defines the static constructor to invoke System.loadLibrary().

    You can distribute the JNI library with the Java wrapper class (or classes) in compiled form, or in text form, as you choose.