JaneaSystems / nodejs-mobile

Full-fledged Node.js on Android and iOS
https://code.janeasystems.com/nodejs-mobile
Other
2.57k stars 182 forks source link

cannot load native addon on android due to failed to locate symbol #70

Open marsbible opened 6 years ago

marsbible commented 6 years ago

Hi all, I just built a native C++ addon by NDK r16b, target arch is arm64,it seems that nodejs-mobile doesn't exports symbols to the C++ module, dlopen() failed due to the symbol miss. Any solution or workaround ? Thanks.

buffertools.tar.gz

05-16 11:27:02.812 28954-28984/com.yourorg.sample E/NODEJS-MOBILE: /data/data/com.yourorg.sample/files/nodejs-project/node_modules/buffertools/buffertools.js:26 if (e.code !== 'MODULE_NOT_FOUND') throw e; ^

Error: dlopen failed: cannot locate symbol "_ZNK2v85Value10Int32ValueEv" referenced by "/data/data/com.yourorg.sample/files/nodejs-project/node_modules/buffertools/build/Release/buffertools.node"...
    at Object.Module._extensions..node (module.js:653:18)
    at Module.load (module.js:545:32)
    at tryModuleLoad (module.js:508:12)
    at Function.Module._load (module.js:500:3)
    at Module.require (module.js:568:17)
    at require (internal/module.js:11:18)
    at Object.<anonymous> (/data/data/com.yourorg.sample/files/nodejs-project/node_modules/buffertools/buffertools.js:24:20)
    at Module._compile (module.js:624:30)
    at Object.Module._extensions..js (module.js:635:10)
    at Module.load (module.js:545:32)
jaimecbernardo commented 6 years ago

Hi, @marsbible ,

Did you use the nodejs-mobile released headers, too?

Regarding dlopen, there are some differences between Android and Linux, described in this issue: https://github.com/android-ndk/ndk/issues/201#issuecomment-248060092 Basically, the android shared library has to be linked to libnode for the symbols to be found at runtime. In the experimental native module support feature for the plugins we add this to the nodejs-mobile headers' common.gypi so gyp does the linking: https://github.com/janeasystems/nodejs-mobile-react-native/blob/05e1748831bca8b8f053dcf80a348f3dc782596c/android/libnode/include/node/common.gypi#L412-L433

In the plugins, we use environment variables while running the build to make sure the nodejs-mobile headers from the plugin are used: https://github.com/janeasystems/nodejs-mobile-react-native/blob/05e1748831bca8b8f053dcf80a348f3dc782596c/android/build.gradle#L294

I hope this is helpful in helping you solve your problem.

marsbible commented 6 years ago

@jaimecbernardo Thank you very much, your info is very helpful, i'll have a try.