HarmonyOS鸿蒙Next中在windows电脑上run的时候报错

HarmonyOS鸿蒙Next中在windows电脑上run的时候报错

【问题描述】:代码运行报错问题

【问题现象】:run的时候出现报错

【版本信息】:开发工具版本:DevEco Studio6.0+,手机系统版本:手机用simulator,Api语言版本:“targetSdkVersion”: “6.0.0(20)”, “compatibleSdkVersion”: “6.0.0(20)”,

【尝试解决方案】:上次的链接给的方法适用于mac开发,windows还是有报错https://developer.huawei.com/consumer/cn/forum/topic/0204141594220444318?fid=0101587866109860105

【复现代码】:

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\arm64-v8a -DOHOS_ARCH=arm64-v8a -DCMAKE_LIBRARY_OUTPUT_DIRECTORY=D:\App\zhere_rn_HarmonyOS\harmony\entry\build\default\intermediates\cmake\default\obj\arm64-v8a -DCMAKE_BUILD_TYPE=Debug -DOHOS_SDK_NATIVE=C:\Huawei\DevEco Studio\sdk\default\openharmony\native -DCMAKE_SYSTEM_NAME=OHOS -DCMAKE_OHOS_ARCH_ABI=arm64-v8a -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\arm64-v8a -DPACKAGE_FIND_FILE=D:\App\zhere_rn_HarmonyOS\harmony\entry.cxx\default\default\debug\hvigor\arm64-v8a\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.

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.

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 arm64, binary format elf, ABI aapcs, assembler gas, suffix .S, implementation fcontext

CMake Error at CMakeLists.txt:15 (add_subdirectory): add_subdirectory given source “/@react-native-ohos/react-native-gesture-handler/src/main/cpp” which is not an existing directory.

– Configuring incomplete, errors occurred!

undefined

  • Try:

Run with --stacktrace option to get the stack trace. Run with --debug option to get more log output. hvigor ERROR: BUILD FAILED in 1 s 329 ms

Process finished with exit code -1


更多关于HarmonyOS鸿蒙Next中在windows电脑上run的时候报错的实战教程也可以访问 https://www.itying.com/category-93-b0.html

3 回复

查看日志发现日志中有以下:

CMake Error at CMakeLists.txt:15 (add_subdirectory):   add_subdirectory given source   “/@react-native-ohos/react-native-gesture-handler/src/main/cpp” which is   not an existing directory.

可以优先排查下这个库的依赖情况。

更多关于HarmonyOS鸿蒙Next中在windows电脑上run的时候报错的实战系列教程也可以访问 https://www.itying.com/category-93-b0.html


在Windows电脑上运行HarmonyOS Next报错,可能涉及以下原因:

  1. 环境配置问题:检查DevEco Studio版本是否支持Next,确保Node.js、SDK、工具链版本匹配Next要求。
  2. 项目配置错误:确认项目使用的API版本、设备类型与Next兼容,检查模块依赖和配置文件。
  3. 系统权限或路径问题:确保项目路径无中文或特殊字符,以管理员身份运行DevEco Studio。
  4. 资源或网络问题:验证本地资源完整,网络连接正常,避免依赖下载失败。

查看DevEco Studio运行日志或控制台输出的具体错误信息,可定位问题。

从错误日志来看,核心问题是CMake在配置阶段失败,具体错误信息为:

add_subdirectory given source "/@react-native-ohos/react-native-gesture-handler/src/main/cpp" which is not an existing directory.

这表明构建系统尝试添加一个名为 @react-native-ohos/react-native-gesture-handler 的依赖模块的C++源码目录,但该路径在您的项目目录中不存在。

这个问题通常由以下几个原因导致:

  1. 依赖未正确安装@react-native-ohos/react-native-gesture-handler 这个OHPM包可能没有成功安装到项目的 oh_modules 目录中。
  2. 路径引用错误:项目中的 CMakeLists.txt 文件(很可能是位于 entry/src/main/cpp 或相关模块的cpp目录下)里,对该依赖的路径配置有误。
  3. 项目缓存或配置不一致:之前的构建缓存或Hvigor的配置信息可能导致路径解析错误。

针对Windows环境的排查和解决步骤:

  1. 验证依赖安装

    • 打开项目根目录下的 oh-package.json5 文件,检查 dependenciesdevDependencies 中是否声明了 @react-native-ohos/react-native-gesture-handler
    • 打开文件资源管理器,导航至项目根目录下的 oh_modules 文件夹,检查是否存在 @react-native-ohos 目录,以及其下的 react-native-gesture-handler 目录结构是否完整,特别是 src/main/cpp 路径是否存在。
  2. 清理并重新安装依赖

    • 在DevEco Studio中,点击底部终端(Terminal)标签页。
    • 执行命令删除现有依赖:ohpm uninstall @react-native-ohos/react-native-gesture-handler
    • 然后执行安装命令:ohpm install @react-native-ohos/react-native-gesture-handler
    • 或者,直接删除整个 oh_modules 目录和 oh-package-lock.json 文件,然后在终端运行 ohpm install 重新安装所有依赖。
  3. 清理构建缓存

    • 在DevEco Studio菜单栏,点击 Build -> Clean Project
    • 也可以手动删除项目根目录下的 build 目录、各模块下的 .cxxbuild 目录。
  4. 检查CMakeLists.txt文件

    • 根据错误日志中提到的 CMakeLists.txt:15(具体行号可能因项目而异),找到对应的 CMakeLists.txt 文件。
    • 检查第15行附近的 add_subdirectory 指令,确认其指向的路径变量或相对路径是否正确。路径应能正确映射到 oh_modules 中实际存在的目录。
  5. 重启DevEco Studio

    • 完成上述步骤后,重启IDE以确保所有更改生效,然后尝试重新运行项目。

这个错误与操作系统(Windows/Mac)关系不大,主要是项目依赖路径解析问题。请按照上述步骤,重点检查依赖的安装完整性和CMake的路径配置。

回到顶部