Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 20 additions & 4 deletions packages/react-native-reanimated/android/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ file(GLOB_RECURSE REANIMATED_ANDROID_CPP_SOURCES CONFIGURE_DEPENDS

find_package(fbjni REQUIRED CONFIG)
find_package(ReactAndroid REQUIRED CONFIG)
find_package(react-native-worklets REQUIRED CONFIG)

add_library(reanimated SHARED ${REANIMATED_COMMON_CPP_SOURCES}
${REANIMATED_ANDROID_CPP_SOURCES})
Expand All @@ -65,13 +64,30 @@ target_include_directories(
"${REACT_NATIVE_DIR}/ReactCommon/runtimeexecutor"
"${REACT_NATIVE_DIR}/ReactCommon/jsiexecutor"
"${REACT_NATIVE_DIR}/ReactCommon/react/renderer/graphics/platform/cxx"
)
"${REACT_NATIVE_WORKLETS_DIR}/Common/cpp"
"${REACT_NATIVE_WORKLETS_DIR}/android/src/main/cpp")

set_target_properties(reanimated PROPERTIES LINKER_LANGUAGE CXX)

target_link_libraries(reanimated log ReactAndroid::jsi fbjni::fbjni android)
if(${CMAKE_BUILD_TYPE} MATCHES "Debug")
set(BUILD_TYPE "debug")
else()
set(BUILD_TYPE "release")
endif()

add_library(worklets SHARED IMPORTED)

set_target_properties(
worklets
PROPERTIES
IMPORTED_LOCATION
"${REACT_NATIVE_WORKLETS_DIR}/android/build/intermediates/cmake/${BUILD_TYPE}/obj/${ANDROID_ABI}/libworklets.so"
)

set_target_properties(reanimated PROPERTIES LINKER_LANGUAGE CXX)

target_link_libraries(reanimated react-native-worklets::worklets)
target_link_libraries(reanimated log ReactAndroid::jsi fbjni::fbjni android
worklets)

if(ReactAndroid_VERSION_MINOR GREATER_EQUAL 76)
target_link_libraries(reanimated ReactAndroid::reactnative)
Expand Down
33 changes: 33 additions & 0 deletions packages/react-native-reanimated/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,28 @@ def resolveReactNativeDirectory() {
)
}

def resolveReactNativeWorkletsDirectory() {
def reactNativeWorkletsLocation = safeAppExtGet("REACT_NATIVE_WORKLETS_NODE_MODULES_DIR", null)
if (reactNativeWorkletsLocation != null) {
return file(reactNativeWorkletsLocation)
}

// Fallback to node resolver for custom directory structures like monorepos.
def reactNativeWorkletsPackage = file(
providers.exec {
workingDir(rootDir)
commandLine("node", "--print", "require.resolve('react-native-worklets/package.json')")
}.standardOutput.asText.get().trim()
)
if (reactNativeWorkletsPackage.exists()) {
return reactNativeWorkletsPackage.parentFile
}

throw new GradleException(
"[Reanimated] Unable to resolve react-native-worklets location in node_modules. You should set project extension property (in `app/build.gradle`) named `REACT_NATIVE_WORKLETS_NODE_MODULES_DIR` with the path to react-native-worklets in node_modules."
)
}

def getReactNativeMinorVersion() {
def reactNativeRootDir = resolveReactNativeDirectory()
def reactProperties = new Properties()
Expand Down Expand Up @@ -102,6 +124,7 @@ if (isNewArchitectureEnabled()) {
}

def reactNativeRootDir = resolveReactNativeDirectory()
def reactNativeWorkletsRootDir = resolveReactNativeWorkletsDirectory()
def REACT_NATIVE_MINOR_VERSION = getReactNativeMinorVersion()
def REANIMATED_VERSION = getReanimatedVersion()
def IS_NEW_ARCHITECTURE_ENABLED = isNewArchitectureEnabled()
Expand Down Expand Up @@ -181,6 +204,7 @@ android {
"-DREACT_NATIVE_MINOR_VERSION=${REACT_NATIVE_MINOR_VERSION}",
"-DANDROID_TOOLCHAIN=clang",
"-DREACT_NATIVE_DIR=${toPlatformFileString(reactNativeRootDir.path)}",
"-DREACT_NATIVE_WORKLETS_DIR=${toPlatformFileString(reactNativeWorkletsRootDir.path)}",
"-DIS_REANIMATED_EXAMPLE_APP=${IS_REANIMATED_EXAMPLE_APP}",
"-DREANIMATED_PROFILING=${REANIMATED_PROFILING}",
"-DREANIMATED_VERSION=${REANIMATED_VERSION}",
Expand Down Expand Up @@ -324,3 +348,12 @@ dependencies {
}

preBuild.dependsOn(prepareReanimatedHeadersForPrefabs)

if (project != rootProject) {
evaluationDependsOn(":react-native-worklets")

afterEvaluate {
tasks.getByName("externalNativeBuildDebug").dependsOn(findProject(":react-native-worklets").tasks.getByName("externalNativeBuildDebug"))
tasks.getByName("externalNativeBuildRelease").dependsOn(findProject(":react-native-worklets").tasks.getByName("externalNativeBuildRelease"))
}
}
2 changes: 1 addition & 1 deletion scripts/lint-cmake.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ if ! which cmake-lint >/dev/null; then
exit 1
fi

cmake-lint "$@"
cmake-lint "$@" --line-width 120