joeferner / node-java

Bridge API to connect with existing Java APIs.
MIT License
1.87k stars 279 forks source link

Failed at the java@0.12.1 install script on MacOS #504

Open danielwsutton opened 4 years ago

danielwsutton commented 4 years ago
> npm install --unsafe-perm java@0.12.1

> node-gyp rebuild

  CXX(target) Release/obj.target/nodejavabridge_bindings/src/java.o
  CXX(target) Release/obj.target/nodejavabridge_bindings/src/javaObject.o
  CXX(target) Release/obj.target/nodejavabridge_bindings/src/javaScope.o
  CXX(target) Release/obj.target/nodejavabridge_bindings/src/methodCallBaton.o
  CXX(target) Release/obj.target/nodejavabridge_bindings/src/nodeJavaBridge.o
  CXX(target) Release/obj.target/nodejavabridge_bindings/src/utils.o
../src/utils.cpp:455:5: warning: ignoring return value of function declared with 'warn_unused_result' attribute [-Wunused-result]
    ((v8::Object*)*v8ex)->Set(Nan::GetCurrentContext(), Nan::New<v8::String>("cause").ToLocalChecked(), javaToV8(java, env, ex));
    ^~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../src/utils.cpp:642:9: warning: ignoring return value of function declared with 'warn_unused_result' attribute [-Wunused-result]
        result->Set(Nan::GetCurrentContext(), i, JavaObject::New(java, obj));
        ^~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../src/utils.cpp:652:9: warning: ignoring return value of function declared with 'warn_unused_result' attribute [-Wunused-result]
        result->Set(Nan::GetCurrentContext(), i, item);
        ^~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../src/utils.cpp:715:9: warning: ignoring return value of function declared with 'warn_unused_result' attribute [-Wunused-result]
        v8ResultNumberObject->Set(Nan::GetCurrentContext(), Nan::New<v8::String>("longValue").ToLocalChecked(), Nan::New<v8::String>(strValue.c_str()).ToLocalChecked());
        ^~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4 warnings generated.
  SOLINK_MODULE(target) Release/nodejavabridge_bindings.node
ld: warning: directory not found for option '-L/Library/Java/JavaVirtualMachines/adoptopenjdk-12.0.2.jdk/Contents/Home/lib/jli'
ld: library not found for -ljli
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [Release/nodejavabridge_bindings.node] Error 1
gyp ERR! build error 
gyp ERR! stack Error: `make` failed with exit code: 2
gyp ERR! stack     at ChildProcess.onExit (/Users/device-farm/.nvm/versions/node/v12.18.3/lib/node_modules/npm/node_modules/node-gyp/lib/build.js:194:23)
gyp ERR! stack     at ChildProcess.emit (events.js:315:20)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:275:12)
gyp ERR! System Darwin 18.7.0
gyp ERR! command "/Users/device-farm/.nvm/versions/node/v12.18.3/bin/node" "/Users/device-farm/.nvm/versions/node/v12.18.3/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /private/tmp/scratchQgRJYF.scratch/test-packagedmveoS/node_modules/smrt-appium-tests/node_modules/java
gyp ERR! node -v v12.18.3
gyp ERR! node-gyp -v v5.1.0
gyp ERR! not ok 
npm WARN smrt-appium-tests@1.0.0 No repository field.
npm WARN smrt-appium-tests@1.0.0 No license field.

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! java@0.12.1 install: `node-gyp rebuild`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the java@0.12.1 install script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/device-farm/.npm/_logs/2020-08-18T17_10_07_477Z-debug.log
npm WARN enoent ENOENT: no such file or directory, open '/private/tmp/scratchQgRJYF.scratch/test-packagedmveoS/package.json'
npm WARN test-packagedmveoS No description
npm WARN test-packagedmveoS No repository field.
npm WARN test-packagedmveoS No README data
npm WARN test-packagedmveoS No license field.

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! smrt-appium-tests@1.0.0 preinstall: `npm install --unsafe-perm java@0.12.1`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the smrt-appium-tests@1.0.0 preinstall script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/device-farm/.npm/_logs/2020-08-18T17_10_08_868Z-debug.log
danielwsutton commented 4 years ago

If you remove the line '-ljli' from binding.gyp this build issue is resolved.

Or if you downgrade jdk to 1.8.

I search for a long time to figure out what jli is for, but couldn't find anything...

I forked, with this change : https://github.com/danielwsutton/node-java/commit/91192d13e6961493eabb96526a9ccc5118005492

However, now i'm running into another error when i go to actually import and use node-java,

dyld: lazy symbol binding failed: Symbol not found: _JNI_CreateJavaVM

based on that i think the '-ljli' is required... so really the only solution i have found that works is downgrading jdx to 1.8....

on JDK 1.8 JRE exist > /Library/Java/JavaVirtualMachines/jdk1.8.0_231.jdk/Contents/Home/jre/lib/jli on JDK 12 it does not... and apparently there never will....

so what exactly can we do here if we want to use node-java on JDK 12+ ?

danielwsutton commented 4 years ago

similar issue, i'll take a look > https://github.com/joeferner/node-java/issues/497

danielwsutton commented 4 years ago

lib_dir="${jre_dir}/jli"

I forked this change, https://github.com/danielwsutton/node-java/commit/1e30ba786a6965fd8df2b643a5d962b06891d4fb

From:

lib_dir="${jre_dir}/jli" 

To:

if [[ -f ${jre_dir}/jli/libjli.dylib ]]; then lib_dir="${jre_dir}"/jli; else lib_dir="${jre_dir}"; fi

So far it seems to be working,

I testing on adoptopenjdk8 and adoptopenjdk12 , your mileage may vary,

danielwsutton commented 4 years ago

I did run into a new issue, but can't seem to repro it locally, only when running it on aws,

  CXX(target) Release/obj.target/nodejavabridge_bindings/src/utils.o
../src/utils.cpp:488:16: error: no member named 'GetBackingStore' in 'v8::ArrayBuffer'
    memcpy(ab->GetBackingStore()->Data(), elems, length);
           ~~  ^

So might not be 100% yet

danielwsutton commented 4 years ago

The above issue with no member named 'GetBackingStore' was resolved by using node 14.8.0

It seems like when you switch to a new version of Java, it forces you into a newer version of Node as well.