It seems that the native Node module you cross-compiled is using N-API, and the error indicates that the symbol napi_fatal_error cannot be located during runtime. This usually happens due to one of the following reasons:
-
Mismatch in Node.js versions: The version of Node.js you used to build the native module might be different from the one you are using as a shared library on Android. Ensure that both versions are the same or, at least, the N-API version used in both is compatible.
-
Incorrect linking: Your native module might not be properly linked with the N-API library. Ensure that you have the proper linking flags set during the cross-compilation process. You should use the node-addon-api or nodejs-mobile as a dependency and include the correct header files.
To fix the issue, try the following steps:
-
Make sure that the Node.js version used in both your development environment and your Android environment is the same or has compatible N-API versions. You can check the N-API version compatibility table here: https://nodejs.org/api/n-api.html#n_api_n_api_version_matrix
-
Ensure that you are using the correct build tools and flags during cross-compilation. If you are using node-gyp, make sure you have the appropriate binding.gyp configuration file. For example, your binding.gyp file should look like:
json
{
"targets": [
{
"target_name": "your_native_module",
"sources": [ "your_native_module_source.cc" ],
"include_dirs": [
"<!@(node -p \"require('node-addon-api').include\")"
],
"dependencies": [
"<!(node -p \"require('node-addon-api').gyp\")"
],
"cflags!": [ "-fno-exceptions" ],
"cflags_cc!": [ "-fno-exceptions" ],
"defines": [ "NAPI_DISABLE_CPP_EXCEPTIONS" ],
"conditions": [
["OS=='android'", {
"libraries": ["-llog"]
}]
]
}
]
}
-
When using nodejs-mobile or any other similar tools, make sure you have properly set up the project according to their guidelines. You can find more information on using nodejs-mobile here: https://github.com/JaneaSystems/nodejs-mobile
-
If you are still facing issues, try rebuilding your native module and your Node.js shared library from scratch, ensuring that you are using the same version and compatible N-API libraries.
By taking these steps, you should be able to resolve the "cannot locate symbol" error and successfully run your native module on Android.