CMake could not find JNI

Related searches

I created a new Android Studio Project with C++ support and did not add anything to it. The project builds, compiles and runs with CMake. I then added the following two lines of code to CMakeLists.txt at the bottom of the file and I get a CMake build error.

find_package(Java COMPONENTS Development)       # Line 47
find_package(JNI REQUIRED)                      # Line 48

And this is the error I get when building the project

-- Found Java: /usr/lib/jvm/java-10-oracle/bin/java (found version "10.0.1") found components:  Development 
-- Configuring incomplete, errors occurred!
CMake Error at /home/xxxxx/Android/Sdk/cmake/3.6.4111459/share/cmake-3.6/Modules/FindPackageHandleStandardArgs.cmake:148 (message):
See also "/home/xxxxx/AndroidStudioProjects/MyApplication/app/.externalNativeBuild/cmake/release/x86_64/CMakeFiles/CMakeOutput.log".
Call Stack (most recent call first):
  /home/xxxxxx/Android/Sdk/cmake/3.6.4111459/share/cmake-3.6/Modules/FindPackageHandleStandardArgs.cmake:388 (_FPHSA_FAILURE_MESSAGE)
  /home/xxxxxx/Android/Sdk/cmake/3.6.4111459/share/cmake-3.6/Modules/FindJNI.cmake:314 (FIND_PACKAGE_HANDLE_STANDARD_ARGS)
  CMakeLists.txt:48 (find_package)
External native generate JSON release: JSON generation completed with problems

CMake runs when being called form the command line, but fails inside Android Studio for some reason and I am not sure why.


Here is the CMakeOutput.log file


This is all that is in CMakeLists.txt file. It compiles in cmd with the command cmake.

cmake_minimum_required(VERSION 3.4.1)

find_package(Java COMPONENTS Development)
find_package(JNI REQUIRED)

This is the cmd output

    E:\Users\xxxxx\AndroidStudioProjects\MyApplication\app\build>cmake ..
-- Configuring done
-- Generating done
-- Build files have been written to: E:/Users/xxxxx/AndroidStudioProjects/MyApplication/app/build

When I try to add it compile it in Android Studio using gradle I get the following error on Windows 10 pro 64 bit

Microsoft Windows [Version 10.0.17134.112]
(c) 2018 Microsoft Corporation. All rights reserved.

E:\Users\xxxxx\AndroidStudioProjects\MyApplication>gradlew build --stacktrace

> Task :app:generateJsonModelDebug 
External native generate JSON debug: starting JSON generation
External native generate JSON debug: using platform version 24 for ABI ARMEABI_V7A and min SDK version 24
External native generate JSON debug: noticing that build file 'E:\Users\xxxxx\AndroidStudioProjects\MyApplication\app\CMakeLists.txt' is out of date with respect to E:\Users\xxxxx\AndroidStudioProjects\MyApplication\app\.extern
External native generate JSON debug: rebuilding JSON E:\Users\xxxxx\AndroidStudioProjects\MyApplication\app\.externalNativeBuild\cmake\debug\armeabi-v7a\android_gradle_build.json due to:
External native generate JSON debug: - a dependent build file changed
External native generate JSON debug: keeping json folder 'E:\Users\xxxxx\AndroidStudioProjects\MyApplication\app\.externalNativeBuild\cmake\debug\armeabi-v7a' but regenerating project
External native generate JSON debug: executing cmake Executable : E:\Android\SDK\cmake\3.6.4111459\bin\cmake.exe
arguments :
-GAndroid Gradle - Ninja
jvmArgs :

CMake Error at E:/Android/SDK/cmake/3.6.4111459/share/cmake-3.6/Modules/FindPackageHandleStandardArgs.cmake:148 (message):
Call Stack (most recent call first):
  E:/Android/SDK/cmake/3.6.4111459/share/cmake-3.6/Modules/FindPackageHandleStandardArgs.cmake:388 (_FPHSA_FAILURE_MESSAGE)
  E:/Android/SDK/cmake/3.6.4111459/share/cmake-3.6/Modules/FindJNI.cmake:314 (FIND_PACKAGE_HANDLE_STANDARD_ARGS)
  CMakeLists.txt:4 (find_package)
-- Configuring incomplete, errors occurred!
See also "E:/Users/xxxxx/AndroidStudioProjects/MyApplication/app/.externalNativeBuild/cmake/debug/armeabi-v7a/CMakeFiles/CMakeOutput.log".

As the CMake version bundled with Android tries to tell you, it can't find the JNI package because some parts were missing:


Checking the documentation for FindJNI ( these variables are set to the locations of libraries and headers not shipped with the Android version of JNI (to little surprise, Android does not included the AWT library for instance). When running find_package(JNI REQUIRED), the FindJNI code checks if these variables are set and if not, issues an error.

A workaround is to set these variables yourself, before calling find_package:

# We are only interested in finding jni.h: we do not care about extended JVM
# functionality or the AWT library.
find_package(JNI REQUIRED)

Be aware though, that your code will only be able to use jni.h and its functionality: if it tries to access any other part of the JNI package it will fail (probably at compile time) because essentially, you have tricked CMake into thinking that the entire package was found, when in reality only a part of it exists in the Android setup.

cmake error(cmake version is � Issue #53 � jvm-profiling , [root@test perf-map-agent]# cmake . -- Could NOT find JNI (missing: JAVA_AWT_LIBRARY JAVA_JVM_LIBRARY JAVA_INCLUDE_PATH� However, these do not help me as I'm unable to understand their responses. Furhtermore, as someone put it in the last link: " I did a websearch for “Could NOT find JNI” cmake FindPackageHandleStandardArgs and this (and similar searches) brings hundreds of results, but only some strange bug reports and build logs without any explaination or


Solved with

sudo apt-get install -y openjdk-8-jdk
sudo apt-get install -y default-jdk
export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64

Could not find JNI java libraries & paths � Issue #181 � uclouvain , cmake:91 (MESSAGE): Could NOT find JNI (missing: JAVA_AWT_LIBRARY JAVA_JVM_LIBRARY JAVA_INCLUDE_PATH� Subject: cmake: Could NOT find JNI (missing: JAVA_AWT_LIBRARY) on powerpc64 Date: Mon, 29 Jul 2013 23:56:04 +0530 Package: cmake Version: 2.8.9-1 Severity: normal Tags: upstream Dear Maintainer, * What led up to the situation?

Same on alpine:edge docker image, fixed using:

ENV JAVA_HOME=/usr/lib/jvm/java-1.8-openjdk
RUN apk add --no-cache openjdk8


FindJNI — CMake 3.0.2 Documentation, FindJNI�. Find JNI java libraries. This module finds if Java is installed and determines where the include files and libraries are. It also determines what the name� I was able to get past this error -- make sure when you run cmake, it's from from the VS x64 native tools command line. Otherwise it attempts to find JNI in the 32bit location for Java trevorbernard closed this on Aug 13, 2014

0014143, Summary, 0014143: FindJNI cannot find JDK installed Could NOT find JNI ( missing: JAVA_AWT_LIBRARY JAVA_JVM_LIBRARY� The "find_package(JNI)" seems could find some of the Java components related to the OpenJDK JRE and could not find my current Oracle Java 7 JDK components pointed by "update-alternatives". I want to know that is there any bug in the "FindJNI.cmake" file and what I have missed in the Oracle Java 7 JDK setup so that cmake "find_package(JNI

1. cmake . JNI not found. 2. del CMakeCache.txt 3. cmake -G "Visual Studio 10 Win64" JNI not found. So it seems CMake re-uses some information other than CMakeCache.txt between configurations which prevents finding JNI. I'm not sure if it is something expected or not. Thanks (0033090) Brad King (manager) 2013-05-17 10:36

Find Java Native Interface (JNI) libraries. JNI enables Java code running in a Java Virtual Machine (JVM) to call and be called by native applications and libraries written in other languages such as C, C++. This module finds if Java is installed and determines where the include files and libraries are.

  • How does this question differ from your previous one?
  • Becuase the last one was trying to compile a GitHub C++ repo which had a Java binding dependency and this one is just trying to figure out why CMake won't find JNI in Android Studio.
  • In the configuration output, See also message shouldn't break "missing" list of variables.
  • Sorry, I do not really understand your comment. What should not be breaking?
  • Lines Could NOT find JNI (missing: JAVA_AWT_LIBRARY JAVA_JVM_LIBRARY, JAVA_INCLUDE_PATH2 JAVA_AWT_INCLUDE_PATH) compound single message, so no "See also " line should come between them. Correct lines sequence can be observed in your previous(deleted) question.
  • Thank you so much for this another NotNeeded cmake voodoo. What do you mean by, if it tries to access any other part of of the JNI package ... ? I'm only interested in hooking my C++ to Java and JNI does that. What else is offered by JNI by the way aside from allowing C++ to link to Java??
  • looks like it's still openjdk-8-jdk as of Feb 2020