HarmonyOS鸿蒙Next中RN运行报错

HarmonyOS鸿蒙Next中RN运行报错

> hvigor ERROR: Failed :entry:default@BuildNativeWithCmake... 
> hvigor ERROR: Exceptions happened while executing C:\Huawei\DevEco Studio\sdk\default\openharmony\native\build-tools\cmake\bin\cmake.exe -HD:\App\zhere_rn_HarmonyOS\harmony\entry\src\main\cpp -BD:\App\zhere_rn_HarmonyOS\harmony\entry\.cxx\default\default\debug\x86_64 -DOHOS_ARCH=x86_64 -DCMAKE_LIBRARY_OUTPUT_DIRECTORY=D:\App\zhere_rn_HarmonyOS\harmony\entry\build\default\intermediates\cmake\default\obj\x86_64 -DCMAKE_BUILD_TYPE=Debug -DOHOS_SDK_NATIVE=C:\Huawei\DevEco Studio\sdk\default\openharmony\native -DCMAKE_SYSTEM_NAME=OHOS -DCMAKE_OHOS_ARCH_ABI=x86_64 -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DCMAKE_TOOLCHAIN_FILE=C:\Huawei\DevEco Studio\sdk\default\hms\native\build\cmake\hmos.toolchain.cmake -GNinja -DCMAKE_MAKE_PROGRAM=C:\Huawei\DevEco Studio\sdk\default\openharmony\native\build-tools\cmake\bin\ninja.exe -DCMAKE_FIND_ROOT_PATH=D:\App\zhere_rn_HarmonyOS\harmony\entry\.cxx\default\default\debug\hvigor\x86_64 -DPACKAGE_FIND_FILE=D:\App\zhere_rn_HarmonyOS\harmony\entry\.cxx\default\default\debug\hvigor\x86_64\summary.cmake --no-warn-unused-cli -DHMOS_SDK_NATIVE=C:\Huawei\DevEco Studio\sdk\default\hms\native.
Not searching for unused variables given on the command line.
-- The C compiler identification is Clang 15.0.4
-- The CXX compiler identification is Clang 15.0.4
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: C:/Huawei/DevEco Studio/sdk/default/openharmony/native/llvm/bin/clang.exe - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: C:/Huawei/DevEco Studio/sdk/default/openharmony/native/llvm/bin/clang++.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
CMake Deprecation Warning at D:/App/zhere_rn_HarmonyOS/harmony/entry/oh_modules/@rnoh/react-native-openharmony/src/main/cpp/CMakeLists.txt:6 (cmake_minimum_required):
  Compatibility with CMake < 3.5 will be removed from a future version of
  CMake.

  Update the VERSION argument <min> value or use a ...<max> suffix to tell
  CMake that the project does not need compatibility with older versions.


ALL_CONTAINERS_CLICKABLE is set to: ON
USE_HERMES is set to: ON
CMake Deprecation Warning at D:/App/zhere_rn_HarmonyOS/harmony/entry/oh_modules/@rnoh/react-native-openharmony/src/main/cpp/third-party/boost/libs/predef/CMakeLists.txt:23 (cmake_minimum_required):
  Compatibility with CMake < 3.5 will be removed from a future version of
  CMake.

  Update the VERSION argument <min> value or use a ...<max> suffix to tell
  CMake that the project does not need compatibility with older versions.


-- Boost.Context: architecture x86_64, binary format elf, ABI sysv, assembler gas, suffix .S, implementation fcontext
-- The ASM compiler identification is Clang 15.0.4 with GNU-like command-line
-- Found assembler: C:/Huawei/DevEco Studio/sdk/default/openharmony/native/llvm/bin/clang.exe
CMake Error at CMakeLists.txt:19 (add_library):
  Syntax error in cmake code at

    D:/App/zhere_rn_HarmonyOS/harmony/entry/src/main/cpp/CMakeLists.txt:20

  when parsing string

    ${GENERATED

  There is an unterminated variable reference.


-- Configuring incomplete, errors occurred!
undefined

更多关于HarmonyOS鸿蒙Next中RN运行报错的实战教程也可以访问 https://www.itying.com/category-93-b0.html

3 回复

开发者你好,根据报错信息,可以检查一下CMakeLists.txt第20行的${GENERATED处配置是否正确。

更多关于HarmonyOS鸿蒙Next中RN运行报错的实战系列教程也可以访问 https://www.itying.com/category-93-b0.html


鸿蒙Next中RN运行报错,通常涉及ArkTS/ArkUI与RN框架的兼容性问题。需检查RN版本是否支持HarmonyOS Next,并确认所有依赖库已适配ArkTS。常见错误源于未使用鸿蒙原生API或NDK接口。请查阅华为官方HarmonyOS应用开发文档,获取RN在鸿蒙Next上的具体配置和限制说明。

从错误信息看,问题出在CMakeLists.txt文件的语法错误。具体是第20行附近存在一个未闭合的变量引用 ${GENERATED

需要检查以下文件: D:/App/zhere_rn_HarmonyOS/harmony/entry/src/main/cpp/CMakeLists.txt

在第19-20行附近,应该有一个 ${GENERATED_SRC_DIR} 或类似的变量引用,但当前写法 ${GENERATED 缺少闭合的 },导致CMake解析失败。

修复方法:

  1. 打开该CMakeLists.txt文件
  2. 找到第20行附近的 ${GENERATED
  3. 将其修正为完整的变量引用,如 ${GENERATED_SRC_DIR} 或根据实际变量名补全
  4. 保存后重新构建

这是典型的CMake语法错误,修正后应该能解决构建问题。

回到顶部