FindJNI — CMake 3.24.2 Documentation

# FindJNI

Find Java Native Interface (JNI) headers and libraries.

JNI enables Java code running in a Java Virtual Machine (JVM) or Dalvik Virtual Machine (DVM) on Android to call and be called by native applications and libraries written in other languages such as C and C++.

This module finds if Java is installed and determines where the include files and libraries are. It also determines what the name of the library is. The caller may set variable `JAVA_HOME` to specify a Java installation prefix explicitly.

New in version 3.24: Added imported targets, components `AWT`, `JVM`, and Android NDK support. If no components are specified, the module defaults to an empty components list while targeting Android, and all available components otherwise.

When using Android NDK, the corresponding package version is reported and a specific release can be requested. At Android API level 31 and above, the additional `NativeHelper` component can be requested. `NativeHelper` is also exposed as an implicit dependency of the `JVM` component (only if this does not cause a conflict) which provides a uniform access to JVM functions.

## Imported Targets

New in version 3.24.

`JNI::JNI`

  Main JNI target, defined only if `jni.h` was found.

`JNI::AWT`

  Java AWT Native Interface (JAWT) library, defined only if component `AWT` was found.

`JNI::JVM`

  Java Virtual Machine (JVM) library, defined only if component `JVM` was found.

`JNI::NativeHelper`

  When targeting Android API level 31 and above, the import target will provide access to `libnativehelper.so` that exposes JVM functions such as `JNI_CreateJavaVM`.

## Result Variables

This module sets the following result variables:

`JNI_INCLUDE_DIRS`

  The include directories to use.

`JNI_LIBRARIES`

  The libraries to use (JAWT and JVM).

`JNI_FOUND`

  `TRUE` if JNI headers and libraries were found.

`JNI_<component>_FOUND`

  New in version 3.24.

  `TRUE` if `<component>` was found.

`JNI_VERSION`

  Full Android NDK package version (including suffixes such as `-beta3` and `-rc1`) or undefined otherwise.

`JNI_VERSION_MAJOR`

  New in version 3.24.

  Android NDK major version or undefined otherwise.

`JNI_VERSION_MINOR`

  New in version 3.24.

  Android NDK minor version or undefined otherwise.

`JNI_VERSION_PATCH`

  New in version 3.24.

  Android NDK patch version or undefined otherwise.

## Cache Variables

The following cache variables are also available to set or use:

`JAVA_AWT_LIBRARY`

  The path to the Java AWT Native Interface (JAWT) library.

`JAVA_JVM_LIBRARY`

  The path to the Java Virtual Machine (JVM) library.

`JAVA_INCLUDE_PATH`

  The include path to `jni.h`.

`JAVA_INCLUDE_PATH2`

  The include path to machine-dependant headers `jni_md.h` and `jniport.h`. The variable is defined only if `jni.h` depends on one of these headers. In contrast, Android NDK `jni.h` can be typically used standalone.

`JAVA_AWT_INCLUDE_PATH`

  The include path to `jawt.h`.