Skip to content

Commit 46488d6

Browse files
committed
Use proper node module resolution to find weak-node-api
1 parent d2755fe commit 46488d6

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

packages/host/android/CMakeLists.txt

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,7 @@ set(CMAKE_CXX_STANDARD 20)
55

66
find_package(ReactAndroid REQUIRED CONFIG)
77
find_package(hermes-engine REQUIRED CONFIG)
8-
9-
add_library(weak-node-api INTERFACE)
10-
target_include_directories(weak-node-api INTERFACE
11-
../../weak-node-api/generated
12-
../../weak-node-api/include
13-
)
8+
find_package(weak-node-api REQUIRED CONFIG)
149

1510
add_library(node-api-host SHARED
1611
src/main/cpp/OnLoad.cpp

packages/host/android/build.gradle

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,17 @@ if (!System.getenv("REACT_NATIVE_OVERRIDE_HERMES_DIR")) {
1414
].join('\n'))
1515
}
1616

17+
def findWeakNodeApiDir() {
18+
def searchDir = rootDir.toPath()
19+
do {
20+
def p = searchDir.resolve("node_modules/weak-node-api")
21+
if (p.toFile().exists()) {
22+
return p.toRealPath().toString()
23+
}
24+
} while (searchDir = searchDir.getParent())
25+
throw new GradleException("Could not find `weak-node-api`");
26+
}
27+
1728
buildscript {
1829
ext.getExtOrDefault = {name ->
1930
return rootProject.ext.has(name) ? rootProject.ext.get(name) : project.properties['NodeApiModules_' + name]
@@ -86,7 +97,7 @@ android {
8697
cmake {
8798
targets "node-api-host"
8899
cppFlags "-frtti -fexceptions -Wall -fstack-protector-all"
89-
arguments "-DANDROID_STL=c++_shared"
100+
arguments "-DANDROID_STL=c++_shared", "-Dweak-node-api_DIR=${findWeakNodeApiDir()}"
90101
abiFilters (*reactNativeArchitectures())
91102

92103
buildTypes {

0 commit comments

Comments
 (0)