HarmonyOS鸿蒙Next中需求:报错00308018,但是官网没有相关说明

HarmonyOS鸿蒙Next中需求:报错00308018,但是官网没有相关说明 【问题描述】:从git上拉下来的项目,本地同步编译,报错00308018,官网没有相关说明

【问题现象】:报错日志和截图

> hvigor ERROR: Failed :entry:default@BuildNativeWithCmake... 
> hvigor ERROR: Error Code: 00308018 Unknown Error
Exceptions happened while executing D:\app\Huawei\DevEco Studio\sdk\default\openharmony\native\build-tools\cmake\bin\cmake.exe -HE:\Checkbox\harmony\entry\src\main\cpp -BE:\Checkbox\harmony\entry\.cxx\default\default\debug\arm64-v8a -DOHOS_ARCH=arm64-v8a -DCMAKE_LIBRARY_OUTPUT_DIRECTORY=E:\Checkbox\harmony\entry\build\default\intermediates\cmake\default\obj\arm64-v8a -DCMAKE_BUILD_TYPE=Debug -DOHOS_SDK_NATIVE=D:\app\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=D:\app\Huawei\DevEco Studio\sdk\default\hms\native\build\cmake\hmos.toolchain.cmake -GNinja -DCMAKE_MAKE_PROGRAM=D:\app\Huawei\DevEco Studio\sdk\default\openharmony\native\build-tools\cmake\bin\ninja.exe -DCMAKE_FIND_ROOT_PATH=E:\Checkbox\harmony\entry\.cxx\default\default\debug\hvigor\arm64-v8a -DPACKAGE_FIND_FILE=E:\Checkbox\harmony\entry\.cxx\default\default\debug\hvigor\arm64-v8a\summary.cmake --no-warn-unused-cli -DHMOS_SDK_NATIVE=D:\app\Huawei\DevEco Studio\sdk\default\hms\native -DOHOS_COMPATIBLE_SDK_VERSION=6.0.0(20).
Not searching for unused variables given on the command line.
CMake Warning (dev) at CMakeLists.txt:1 (project):
  cmake_minimum_required() should be called prior to this top-level project()
  call.  Please see the cmake-commands(7) manual for usage documentation of
  both commands.
This warning is for project developers.  Use -Wno-dev to suppress it.

-- 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: D:/app/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: D:/app/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 CMakeLists.txt:2 (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.


CMake Deprecation Warning at E:/Checkbox/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 E:/Checkbox/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
-- The ASM compiler identification is Clang 15.0.4 with GNU-like command-line
-- Found assembler: D:/app/Huawei/DevEco Studio/sdk/default/openharmony/native/llvm/bin/clang.exe
CMake Error at CMakeLists.txt:16 (add_subdirectory):
  add_subdirectory given source
  "E:/Checkbox/harmony/entry/src/main/cpp/../../../oh_modules/@react-native-ohos/checkbox/src/main/cpp"
  which is not an existing directory.


-- Configuring incomplete, errors occurred!
undefined

* Try the following:
  > This error is unknown, view the detailed error logs in the '.hvigor > outputs > build-logs' directory in the project directory for analysis, or contact the developer's official website for help.
  > More info: https://developer.huawei.com/consumer/cn/doc/harmonyos-faqs/faqs-compiling-and-building


* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --debug option to get more log output.

> hvigor ERROR: BUILD FAILED in 3 s 131 ms 

Process finished with exit code -1

cke_11608.png

【版本信息】:

开发工具版本

cke_3704.png

RN的package

{
  "name": "AwesomeProject",
  "version": "0.0.1",
  "private": true,
  "scripts": {
    "android": "react-native run-android",
    "ios": "react-native run-ios",
    "lint": "eslint .",
    "start": "hdc rport tcp:8081 tcp:8081 && react-native start --config metro.config.harmony.js",
    "test": "jest",
    "dev": "react-native bundle-harmony --dev"
  },
  "dependencies": {
    "@react-native-oh/react-native-harmony": "^0.72.108",
    "@react-native-ohos/checkbox": "^0.5.17-rc.4",
    "@react-navigation/native": "^7.1.33",
    "@react-navigation/native-stack": "^7.14.4",
    "react": "18.2.0",
    "react-native": "0.72.5",
    "react-native-safe-area-context": "^5.7.0",
    "react-native-screens": "^4.24.0"
  },
  "devDependencies": {
    "@babel/core": "^7.20.0",
    "@babel/preset-env": "^7.20.0",
    "@babel/runtime": "^7.20.0",
    "@react-native/eslint-config": "^0.72.2",
    "@react-native/metro-config": "^0.72.11",
    "@tsconfig/react-native": "^3.0.0",
    "@types/react": "^18.0.24",
    "@types/react-test-renderer": "^18.0.0",
    "babel-jest": "^29.2.1",
    "eslint": "^8.19.0",
    "jest": "^29.2.1",
    "metro-react-native-babel-preset": "0.76.8",
    "prettier": "^2.4.1",
    "react-test-renderer": "18.2.0",
    "typescript": "4.8.4"
  },
  "engines": {
    "node": ">=16"
  }
}

harmony的package

{
  "modelVersion": "6.0.0",
  "description": "Please describe the basic information.",
  "dependencies": {},
  "devDependencies": {
    "@ohos/hypium": "1.0.24",
    "@ohos/hamock": "1.0.0"
  },
  "dynamicDependencies": {}
}

harmony/entry的package

{
  "name": "entry",
  "version": "1.0.0",
  "description": "Please describe the basic information.",
  "main": "",
  "author": "",
  "license": "",
  "dependencies": {
    "@rnoh/react-native-openharmony": "0.72.108"
  },
  "devDependencies": {},
  "dynamicDependencies": {}
}

更多关于HarmonyOS鸿蒙Next中需求:报错00308018,但是官网没有相关说明的实战教程也可以访问 https://www.itying.com/category-93-b0.html

9 回复

尊敬的开发者,您好,问题已修复,还请参考最新的操作异常错误码文档验证,感谢。

更多关于HarmonyOS鸿蒙Next中需求:报错00308018,但是官网没有相关说明的实战系列教程也可以访问 https://www.itying.com/category-93-b0.html


应该是缓存的问题,我清理了好几次缓存,重启电脑后没问题了

找HarmonyOS工作还需要会Flutter的哦,有需要Flutter教程的可以学学大地老师的教程,很不错,B站免费学的哦:https://www.bilibili.com/video/BV1S4411E7LY/?p=17

尊敬的开发者,您好!感谢您的反馈,问题正在加速处理中,还请关注后续版本,感谢您的理解与支持。

我也遇到过,clean后就正常了

可以看看其他论坛贴子:报错00305008。或者提供下git链接看看。

这个好像是更新Deveco Studio后出现的,之前没有遇到过,这个项目之前是好的,没有任何修改

错误码00308018通常对应鸿蒙Next的API权限或资源访问冲突。常见于调用系统级能力时未正确声明ohos.permission或使用已废弃接口。请检查模块的module.json5中权限配置,并确认SDK版本与API文档对齐。若源码涉及多线程锁或回调未同步也可能触发该码。

错误码 00308018 是 CMake Native 构建阶段的通用错误,本身无特定含义,需从日志定位具体问题。

你的构建日志中关键报错为:

CMake Error at CMakeLists.txt:16 (add_subdirectory):
  add_subdirectory given source
  "E:/Checkbox/harmony/entry/src/main/cpp/../../../oh_modules/@react-native-ohos/checkbox/src/main/cpp"
  which is not an existing directory.

原因:entry 模块的 CMakeLists.txt 中引用了 @react-native-ohos/checkbox 的 native 源码目录,但该路径实际不存在,即这个第三方库的 native 代码没有正确安装或链接到项目中。

结合你的项目是 RN 鸿蒙化工程,通常是因为 @react-native-ohos/checkbox 对应的 oh_module 未正确安装,或软链接(oh_modules)失效。

解决

  • 检查 harmony/entry/oh_modules/ 下是否存在 @react-native-ohos/checkbox 目录且包含 src/main/cpp/CMakeLists.txt。若不存在,在 HarmonyOS 项目根目录执行 ohpm install 重新安装依赖。
  • 由于你从 Git 拉取项目,oh_modules 可能被 .gitignore 排除,需要重新执行 ohpm install 后再同步编译。
回到顶部