Skip to content

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

@emperorjm

Description

@emperorjm

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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions