dart-lang / native

Dart packages related to FFI and native assets bundling.
BSD 3-Clause "New" or "Revised" License
82 stars 27 forks source link

Windows build fails with Could NOT find JNI #1105

Closed bawahakim closed 3 weeks ago

bawahakim commented 3 weeks ago

First of all, sorry if this is the wrong place to report. I've seen the issue in Stack Overflow, but it only seems to apply to Android builds.

Background I do not use JNI directly, it's been used through a dependency of native_dio_adapter. We only need that package for Android and iOS. I can build on Android fine from my Windows machine when the package is added.

However, if i try to build for Windows, the build fails with the error below

CMake Error at C:/Program Files (x86)/Microsoft Visual Studio/2022/BuildTools/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.26/Modules/FindPackageHandleStandardArgs.cmake:230 (message):
  Could NOT find JNI (missing: JAVA_INCLUDE_PATH JAVA_INCLUDE_PATH2 AWT)
Call Stack (most recent call first):
  C:/Program Files (x86)/Microsoft Visual Studio/2022/BuildTools/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.26/Modules/FindPackageHandleStandardArgs.cmake:600 (_FPHSA_FAILURE_MESSAGE)
  C:/Program Files (x86)/Microsoft Visual Studio/2022/BuildTools/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.26/Modules/FindJNI.cmake:569 (find_package_handle_standard_args)
  flutter/ephemeral/.plugin_symlinks/jni/src/CMakeLists.txt:32 (find_package)

Error: Unable to generate build files

I am faced with two options:

  1. Try to fix the error itself
  2. Exclude the plugin for Windows

In the first case, it would mean any developper would need to (unecessarily) follow steps to fix the missing env vars on their system. So I'd think the second option would be best.

However, there is no way as I understand to disable the plugin for Windows, except creating a fork and explictly removing windows for the ffiPlugin definition in the pubspec.

Is there any other way to disable the plugin, or should I just rely on a fork?

Thank you!

bawahakim commented 3 weeks ago

Update: easily fixed the JNI not found issue. The reason was that JAVA_HOME pointed to Android Studio version of Java, which does not seem to support JNI. Installing JDK 17 and pointing JAVA_HOME to it resolved the issue.