react-native-libsodium icon indicating copy to clipboard operation
react-native-libsodium copied to clipboard

Android build fails due to invalid escape sequence in CMakeLists.txt

Open emperorjm opened this issue 9 months ago • 1 comments

Environment

  • OS: Windows 11
  • React Native: 0.73.x (via Expo SDK 50)
  • Node: v18+
  • Android NDK: 27.1.12297006
  • CMake: 3.22.1
  • react-native-libsodium: latest

Problem

I'm unable to build the Android project due to a syntax error in the CMake configuration:

CMake Error at CMakeLists.txt:42 (add_library): Syntax error in cmake code when parsing string

C:\Projects\abstraxion-expo-demo\node_modules/react-native/ReactCommon/jsi/jsi/jsi.cpp

Invalid character escape '\P'.

This is caused by backslashes in Windows paths being interpreted as escape characters by CMake (e.g. \P).

Temporary Workaround

No clean workaround yet besides manual patching CMakeList.txt file:

# Convert NODE_MODULES_DIR to a CMake-friendly path
file(TO_CMAKE_PATH "${NODE_MODULES_DIR}" SAFE_NODE_MODULES_DIR)

# Construct the JSI CPP path using the safe path and forward slashes
set(JSI_CPP_PATH "${SAFE_NODE_MODULES_DIR}/react-native/ReactCommon/jsi/jsi/jsi.cpp")

# here we define a library target called "libsodium"
# which will be built from the listed source files
add_library(libsodium
  SHARED
  "${JSI_CPP_PATH}" # Use the corrected path variable
  ../cpp/react-native-libsodium.cpp
  ../cpp/react-native-libsodium.h
  cpp-adapter.cpp
)

I would appreciate a fix or workaround that supports Windows dev environments out of the box.

Thanks!

emperorjm avatar Jul 01 '25 01:07 emperorjm

Found this https://dev.to/kaif-shariff/cmake-d-escape-sequence-error-during-react-native-cli-setup-on-windows-4bac

LiamKarlMitchell avatar Sep 09 '25 06:09 LiamKarlMitchell

I'm open to a PR, but I don't focus on building on windows myself. Don't have a windows machine atm

nikgraf avatar Nov 16 '25 18:11 nikgraf