We put some useful script in package.json file:
"scripts": {
"compress": "node js_task/compress.js",
"combine": "node js_task/combine_compile_commands.js",
"valid": "ROOT_DIR=$(pwd) node ./js_task/valid_task/valid.js",
"start": "npm run compress && http-server -p 20490"
},compress: each NAPI module which needs to be exported in js is export byglobalThis.ModuleApiName = process._linkedBinding("ModuleName").ApiName;. These js code are put in**/preload_script.jsfile, which will be converted to c string saved in**/preload_script.hpp. This process is handled bycompresscommand.combine: cpp code of this project is developed in vscode, so we need to add all relative file paths to thecompileCommandsoptions of.vscode/c_cpp_properties.json. These cpp relative files will be created when do build in Android Studio,combinecommand is used to collect and add them to.vscode/compile_commands.json, then vscode can recognize cpp symbol.valid: Use to check if WaveProducer, a tool used in OscillatorNode, works correctly.start: docompressand start a http-server accessed by app to load js code which need to be run.
If you write cpp layer in vscode, you should build once after Android Studio sync. Build will trigger combine command which makes vscode recognize cpp symbol.
NOTE: if you find vscode not recognize cpp symbol, make sure to switch the Android Studio tab to app/build.gradle.kts, then build.
If you find pre-commit in husky run when execute git commit will occurs some errors about system header, but these errors are disappear when execute npx lint-staged in terminal, just ignore them with --no-verify such as git commit -m "xxx" --no-verify.
Or if you fix that, please tell me how to do it by create Issue, Thanks!
The libnode.so built with nodejs-mobile on macOS in lima and containerd x86_64 linux vm. More detail please read build_nodejs.md.
The goal of the project architecture is to make the structure of the napi layer consistent with the cpp layer. But NAPI do not support inheritance, so we make a patch to NAPI, that is NAPI_IH.
If you meet crash, please follow the steps below to clean all cache of cpp and android:
- delete
app/buildfolder - delete
app/audio/.cxxandapp/audio/buildfolder - delete
app/node_env/.cxxandapp/node_env/buildfolder - open Android Studio, select Build -> Clean Project
- open Android Studio, select File -> Invalidate Cache, check all options that you can check, then select Invalidate and Restart.
- Rebuild project and run
If crash still exists, please create issues with your android studio log.
It's also a good idea to debug with debug version of NodeJS so.