How to Resolve "Could Not Find Jni", Building Opencv on Raspberry Pi

CMake could not find JNI

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

missing: JAVA_AWT_LIBRARY JAVA_JVM_LIBRARY JAVA_INCLUDE_PATH2 JAVA_AWT_INCLUDE_PATH

Checking the documentation for FindJNI (https://cmake.org/cmake/help/latest/module/FindJNI.html) 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.
set(JAVA_AWT_LIBRARY NotNeeded)
set(JAVA_JVM_LIBRARY NotNeeded)
set(JAVA_INCLUDE_PATH2 NotNeeded)
set(JAVA_AWT_INCLUDE_PATH NotNeeded)
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 cannot recognize java while building OpenCv

I don't think this will be the best way to solve this problem, but i solve it this way:

  1. installing cmake-gui (sudo apt-get install cmake-gui)
  2. removing the content of the build folder (to start again)
  3. start cmake-gui and configure the build
  4. enable BUILD_JAVA param
  5. add new entry titled JAVA_HOME that points to the java home directory
  6. configure build again

then cmake successfully recognized java

Build of OpenCV getting errors, are these serious?

you need to work on virtual enviroment restart with
$ mkvirtualenv cv -p python2



Related Topics



Leave a reply



Submit