diff --git a/.changeset/big-hornets-wear.md b/.changeset/big-hornets-wear.md new file mode 100644 index 00000000..b0409501 --- /dev/null +++ b/.changeset/big-hornets-wear.md @@ -0,0 +1,5 @@ +--- +"@react-native-node-api/test-app": patch +--- + +Renamed ferric-example in test app to match mono-repo packages diff --git a/.changeset/upset-papayas-pump.md b/.changeset/upset-papayas-pump.md new file mode 100644 index 00000000..fc24d488 --- /dev/null +++ b/.changeset/upset-papayas-pump.md @@ -0,0 +1,5 @@ +--- +"react-native-node-api": patch +--- + +Fix host library to not explicitly link with weak-node-api and instead rely on dlopen diff --git a/apps/test-app/App.tsx b/apps/test-app/App.tsx index 62c59944..397409bb 100644 --- a/apps/test-app/App.tsx +++ b/apps/test-app/App.tsx @@ -72,7 +72,7 @@ function loadTests({ it("exports a callable sum function", () => { const exampleAddon = /* eslint-disable-next-line @typescript-eslint/no-require-imports -- TODO: Determine why a dynamic import doesn't work on Android */ - require("ferric-example") as typeof import("ferric-example"); + require("@react-native-node-api/ferric-example") as typeof import("@react-native-node-api/ferric-example"); const result = exampleAddon.sum(1, 3); if (result !== 4) { throw new Error(`Expected 1 + 3 to equal 4, but got ${result}`); diff --git a/apps/test-app/package.json b/apps/test-app/package.json index 4f52b082..b14c03df 100644 --- a/apps/test-app/package.json +++ b/apps/test-app/package.json @@ -25,6 +25,7 @@ "@react-native-community/cli": "^18.0.0", "@react-native-community/cli-platform-android": "^18.0.0", "@react-native-community/cli-platform-ios": "^18.0.0", + "@react-native-node-api/ferric-example": "*", "@react-native-node-api/node-addon-examples": "*", "@react-native-node-api/node-tests": "*", "@react-native/babel-preset": "0.79.0", @@ -34,7 +35,6 @@ "@types/mocha": "^10.0.10", "@types/react": "^19.0.0", "concurrently": "^9.1.2", - "ferric-example": "^0.1.0", "mocha": "^11.6.0", "mocha-remote-cli": "^1.13.2", "mocha-remote-react-native": "^1.13.2", diff --git a/package-lock.json b/package-lock.json index 12ad7aa0..52c6cb69 100644 --- a/package-lock.json +++ b/package-lock.json @@ -36,7 +36,7 @@ }, "apps/test-app": { "name": "@react-native-node-api/test-app", - "version": "0.1.1", + "version": "0.1.2", "dependencies": { "@babel/core": "^7.26.10", "@babel/preset-env": "^7.26.9", @@ -44,6 +44,7 @@ "@react-native-community/cli": "^18.0.0", "@react-native-community/cli-platform-android": "^18.0.0", "@react-native-community/cli-platform-ios": "^18.0.0", + "@react-native-node-api/ferric-example": "*", "@react-native-node-api/node-addon-examples": "*", "@react-native-node-api/node-tests": "*", "@react-native/babel-preset": "0.79.0", @@ -53,7 +54,6 @@ "@types/mocha": "^10.0.10", "@types/react": "^19.0.0", "concurrently": "^9.1.2", - "ferric-example": "^0.1.0", "mocha": "^11.6.0", "mocha-remote-cli": "^1.13.2", "mocha-remote-react-native": "^1.13.2", @@ -9083,10 +9083,6 @@ "resolved": "packages/ferric", "link": true }, - "node_modules/ferric-example": { - "resolved": "packages/ferric-example", - "link": true - }, "node_modules/file-entry-cache": { "version": "8.0.0", "resolved": "https://registry.npmjs.org/file-entry-cache/-/file-entry-cache-8.0.0.tgz", @@ -14333,7 +14329,7 @@ } }, "packages/cmake-rn": { - "version": "0.2.3", + "version": "0.3.0", "dependencies": { "@commander-js/extra-typings": "^13.1.0", "bufout": "^0.3.2", @@ -14341,7 +14337,7 @@ "cmake-js": "^7.3.1", "commander": "^13.1.0", "ora": "^8.2.0", - "react-native-node-api": "0.3.2" + "react-native-node-api": "0.3.3" }, "bin": { "cmake-rn": "bin/cmake-rn.js" @@ -14566,7 +14562,7 @@ }, "packages/ferric": { "name": "ferric-cli", - "version": "0.2.3", + "version": "0.3.0", "dependencies": { "@commander-js/extra-typings": "^13.1.0", "@napi-rs/cli": "~3.0.3", @@ -14574,7 +14570,7 @@ "chalk": "^5.4.1", "commander": "^13.1.0", "ora": "^8.2.0", - "react-native-node-api": "0.3.2" + "react-native-node-api": "0.3.3" }, "bin": { "ferric": "bin/ferric.js" @@ -14582,7 +14578,7 @@ }, "packages/ferric-example": { "name": "@react-native-node-api/ferric-example", - "version": "0.1.0", + "version": "0.1.1", "devDependencies": { "ferric-cli": "*" } @@ -14831,7 +14827,7 @@ }, "packages/host": { "name": "react-native-node-api", - "version": "0.3.2", + "version": "0.3.3", "license": "MIT", "dependencies": { "@commander-js/extra-typings": "^13.1.0", @@ -15455,7 +15451,7 @@ "cmake-rn": "*", "gyp-to-cmake": "*", "prebuildify": "^6.0.1", - "react-native-node-api": "^0.3.2", + "react-native-node-api": "^0.3.3", "read-pkg": "^9.0.1", "rolldown": "1.0.0-beta.29" } diff --git a/packages/host/android/CMakeLists.txt b/packages/host/android/CMakeLists.txt index d062762a..3e9fd392 100644 --- a/packages/host/android/CMakeLists.txt +++ b/packages/host/android/CMakeLists.txt @@ -6,10 +6,7 @@ set(CMAKE_CXX_STANDARD 20) find_package(ReactAndroid REQUIRED CONFIG) find_package(hermes-engine REQUIRED CONFIG) -add_library(weak-node-api SHARED IMPORTED) -set_target_properties(weak-node-api PROPERTIES - IMPORTED_LOCATION "${CMAKE_SOURCE_DIR}/../weak-node-api/weak-node-api.android.node/${ANDROID_ABI}/libweak-node-api.so" -) +add_library(weak-node-api INTERFACE) target_include_directories(weak-node-api INTERFACE ../weak-node-api ../weak-node-api/include @@ -31,6 +28,7 @@ target_include_directories(node-api-host PRIVATE ) target_link_libraries(node-api-host + PRIVATE # android log ReactAndroid::reactnative diff --git a/packages/host/android/build.gradle b/packages/host/android/build.gradle index 946922a6..ee47d91a 100644 --- a/packages/host/android/build.gradle +++ b/packages/host/android/build.gradle @@ -48,6 +48,8 @@ android { sourceSets { main { manifest.srcFile "src/main/AndroidManifestNew.xml" + // Include the weak-node-api to enable a dynamic load + jniLibs.srcDirs += ["../weak-node-api/weak-node-api.android.node"] } } } diff --git a/packages/host/cpp/RuntimeNodeApi.cpp b/packages/host/cpp/RuntimeNodeApi.cpp index 58309ed6..3c4d773c 100644 --- a/packages/host/cpp/RuntimeNodeApi.cpp +++ b/packages/host/cpp/RuntimeNodeApi.cpp @@ -31,8 +31,9 @@ napi_status napi_create_buffer_copy(napi_env env, return napi_invalid_arg; } - void* buffer = nullptr; - if (const auto status = ::napi_create_buffer(env, length, &buffer, result); + void *buffer = nullptr; + if (const auto status = callstack::nodeapihost::napi_create_buffer( + env, length, &buffer, result); status != napi_ok) { return status; }