HarmonyOS鸿蒙Next中Flutter开发应用运行失败:error: unknown command 'clean'

HarmonyOS鸿蒙Next中Flutter开发应用运行失败:error: unknown command ‘clean’

Setting up EMSDK environment (suppress these messages with EMSDK_QUIET=1)

Adding directories to PATH:

PATH += /Users/chengzan/emsdk

PATH += /Users/chengzan/emsdk/upstream/emscripten

Setting environment variables:

PATH = /Users/chengzan/emsdk:/Users/chengzan/emsdk/upstream/emscripten:/opt/homebrew/bin:/opt/homebrew/sbin:/usr/local/bin:/System/Cryptexes/App/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Applications/VMware Fusion.app/Contents/Public:/Library/Apple/usr/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/local/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/appleinternal/bin

EMSDK = /Users/chengzan/emsdk

EMSDK_NODE = /Users/chengzan/emsdk/node/16.20.0_64bit/bin/node

EMSDK_PYTHON = /Users/chengzan/emsdk/python/3.9.2_64bit/bin/python3

SSL_CERT_FILE = /Users/chengzan/emsdk/python/3.9.2_64bit/lib/python3.9/site-packages/certifi/cacert.pem

chengzan@chengzandeMac-Studio-514 hello_world % flutter create --platforms ohos .

Recreating project ....

  test/widget_test.dart (created)

  hello_world.iml (created)

  .gitignore (created)

  analysis_options.yaml (created)

  ohos/hvigor/hvigor-config.json5 (created)

  ohos/entry/oh-package.json5 (created)

  ohos/entry/hvigorfile.ts (created)

  ohos/entry/.gitignore (created)

  ohos/entry/build-profile.json5 (created)

  ohos/entry/src/ohosTest/resources/base/element/color.json (created)

  ohos/entry/src/ohosTest/resources/base/element/string.json (created)

  ohos/entry/src/ohosTest/resources/base/profile/test_pages.json (created)

  ohos/entry/src/ohosTest/resources/base/media/icon.png (created)

  ohos/entry/src/ohosTest/module.json5 (created)

  ohos/entry/src/ohosTest/ets/testrunner/OpenHarmonyTestRunner.ts (created)

  ohos/entry/src/ohosTest/ets/test/List.test.ets (created)

  ohos/entry/src/ohosTest/ets/test/Ability.test.ets (created)

  ohos/entry/src/ohosTest/ets/testability/TestAbility.ets (created)

  ohos/entry/src/ohosTest/ets/testability/pages/Index.ets (created)

  ohos/entry/src/main/resources/en_US/element/string.json (created)

  ohos/entry/src/main/resources/zh_CN/element/string.json (created)

  ohos/entry/src/main/resources/base/element/color.json (created)

  ohos/entry/src/main/resources/base/element/string.json (created)

  ohos/entry/src/main/resources/base/profile/main_pages.json (created)

  ohos/entry/src/main/resources/base/media/icon.png (created)

  ohos/entry/src/main/module.json5 (created)

  ohos/entry/src/main/ets/entryability/EntryAbility.ets (created)

  ohos/entry/src/main/ets/pages/Index.ets (created)

  ohos/oh-package.json5 (created)

  ohos/hvigorfile.ts (created)

  ohos/.gitignore (created)

  ohos/AppScope/resources/base/element/string.json (created)

  ohos/AppScope/resources/base/media/app_icon.png (created)

  ohos/AppScope/app.json5 (created)

  ohos/build-profile.json5 (created)

  .idea/runConfigurations/main_dart.xml (created)

  .idea/libraries/KotlinJavaRuntime.xml (created)

Running "flutter pub get" in hello_world...

Resolving dependencies... 

  _fe_analyzer_shared 50.0.0 (92.0.0 available)

  analyzer 5.2.0 (9.0.0 available)

  archive 3.3.2 (4.0.7 available)

  args 2.3.1 (2.7.0 available)

  async 2.10.0 (2.13.0 available)

  boolean_selector 2.1.1 (2.1.2 available)

  characters 1.2.1 (1.4.1 available)

  clock 1.1.1 (1.1.2 available)

  collection 1.17.0 (1.19.1 available)

  convert 3.1.1 (3.1.2 available)

  coverage 1.6.1 (1.15.0 available)

  crypto 3.0.2 (3.0.6 available)

  fake_async 1.3.1 (1.3.3 available)

  file 6.1.4 (7.0.1 available)

  frontend_server_client 3.1.0 (4.0.0 available)

  glob 2.1.1 (2.1.3 available)

  http_multi_server 3.2.1 (3.2.2 available)

  http_parser 4.0.2 (4.1.2 available)

  io 1.0.3 (1.0.5 available)

  js 0.6.5 (discontinued)

  logging 1.1.0 (1.3.0 available)

  matcher 0.12.13 (0.12.17 available)

  material_color_utilities 0.2.0 (0.13.0 available)

  meta 1.8.0 (1.17.0 available)

  mime 1.0.2 (2.0.0 available)

  node_preamble 2.0.1 (2.0.2 available)

  package_config 2.1.0 (2.2.0 available)

  path 1.8.2 (1.9.1 available)

  platform 3.1.0 (3.1.6 available)

  pool 1.5.1 (1.5.2 available)

  process 4.2.4 (5.0.5 available)

  pub_semver 2.1.3 (2.2.0 available)

  shelf 1.4.0 (1.4.2 available)

  shelf_packages_handler 3.0.1 (3.0.2 available)

  shelf_static 1.1.1 (1.1.3 available)

  shelf_web_socket 1.0.3 (3.0.0 available)

  source_map_stack_trace 2.1.1 (2.1.2 available)

  source_maps 0.10.11 (0.10.13 available)

  source_span 1.9.1 (1.10.1 available)

  stack_trace 1.11.0 (1.12.1 available)

  stream_channel 2.1.1 (2.1.4 available)

  string_scanner 1.2.0 (1.4.1 available)

  term_glyph 1.2.1 (1.2.2 available)

  test 1.22.0 (1.26.3 available)

  test_api 0.4.16 (0.7.7 available)

  test_core 0.4.20 (0.6.12 available)

  typed_data 1.3.1 (1.4.0 available)

  vector_math 2.1.4 (2.2.0 available)

  vm_service 9.4.0 (15.0.2 available)

  watcher 1.0.2 (1.1.4 available)

  web_socket_channel 2.2.0 (3.0.3 available)

  webdriver 3.0.1 (3.1.0 available)

  webkit_inspection_protocol 1.2.0 (1.2.1 available)

  yaml 3.1.1 (3.1.3 available)

Got dependencies!

Wrote 37 files.

All done!

You can find general documentation for Flutter at: https://docs.flutter.dev/

Detailed API documentation is available at: https://api.flutter.dev/

If you prefer video documentation, consider: https://www.youtube.com/c/flutterdev

In order to run your application, type:

  $ cd .

  $ flutter run

Your application code is in ./lib/main.dart.

chengzan@chengzandeMac-Studio-514 hello_world % flutter run

Flutter assets will be downloaded from https://storage.flutter-io.cn. Make sure you trust this source!

Downloading Web SDK...                                   36.3s

Downloading CanvasKit...                               2,334ms

Downloading darwin-x64/FlutterMacOS.framework tools...     10.6s

Downloading darwin-x64/gen_snapshot tools...               3.1s

Downloading darwin-x64-profile/FlutterMacOS.framework tools...   6.6s

Downloading darwin-x64-profile tools...                 1,172ms

Downloading darwin-x64-profile/gen_snapshot tools...       2,377ms

Downloading darwin-x64-release/FlutterMacOS.framework tools...   4.2s

Downloading darwin-x64-release tools...                 1,217ms

Downloading darwin-x64-release/gen_snapshot tools...       2,800ms

Launching lib/main.dart on 127.0.0.1:5555 in debug mode...

start hap build...

error: unknown command 'clean'

ProcessException: The command failed

  Command: ohpm clean

Running Hvigor task assembleHap...   
Doctor summary (to see all details, run flutter doctor -v):
[!] Flutter (Channel br_3.7.12-ohos-dev, 3.7.12-ohos-1.1.2-Beta1, on macOS
    13.5.2 22G91 darwin-arm64, locale zh-Hans-CN)
    ! Upstream repository
      https://gitcode.com/openharmony-sig/flutter_flutter.git is not a standard
      remote.
      Set environment variable "FLUTTER_GIT_URL" to
      https://gitcode.com/openharmony-sig/flutter_flutter.git to dismiss this
      error.
[✓] HarmonyOS toolchain - develop for HarmonyOS devices
[!] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
    ✗ cmdline-tools component is missing
      Run `path/to/sdkmanager --install "cmdline-tools;latest"`
      See https://developer.android.com/studio/command-line for more details.
    ✗ Android license status unknown.
      Run `flutter doctor --android-licenses` to accept the SDK licenses.
      See https://flutter.dev/docs/get-started/install/macos#android-setup for
      more details.
[✓] Xcode - develop for iOS and macOS (Xcode 15.2)
[✓] Chrome - develop for the web
[!] Android Studio (version 2023.2)
    ✗ Unable to find bundled Java version.
[✓] IntelliJ IDEA Ultimate Edition (version 2023.2)
[✓] VS Code (version 1.105.1)
[✓] Connected device (3 available)
[✓] HTTP Host Availability

! Doctor found issues in 3 categories.

更多关于HarmonyOS鸿蒙Next中Flutter开发应用运行失败:error: unknown command 'clean'的实战教程也可以访问 https://www.itying.com/category-92-b0.html

4 回复

已解决,更新DevEco-Studio后需要更新command-line-tools

更多关于HarmonyOS鸿蒙Next中Flutter开发应用运行失败:error: unknown command 'clean'的实战系列教程也可以访问 https://www.itying.com/category-92-b0.html


因为DevEco Studio 与 command-line-tools 版本不匹配

DevEco Studio 是鸿蒙开发的集成环境,command-line-tools 是配套的命令行工具集,需要保持版本一致才能正常

步骤:在设置中找到 Appearance & Behavior > System Settings > HarmonyOS SDK

找到Command Line Tools选项,勾选与当前DevEco Studio版本一致的工具版本即可

在HarmonyOS Next中使用Flutter时,'clean’命令无法识别是因为Flutter的某些命令与鸿蒙开发环境不兼容。鸿蒙Next对Flutter的支持可能有限,导致部分标准Flutter命令无法执行。请检查Flutter版本是否与HarmonyOS Next兼容,并确认开发环境配置正确。建议查阅鸿蒙官方文档中关于Flutter集成的具体说明,以获取适用的命令和操作指南。

这个错误是因为 Flutter 的 HarmonyOS 分支在构建过程中尝试执行 ohpm clean 命令,但当前版本的 ohpm 工具不支持该命令。

从日志可以看出,项目创建成功,依赖解析也正常,但在执行 flutter run 时,Hvigor 构建系统调用了 ohpm clean 命令导致失败。

解决方案:

  1. 检查 ohpm 版本,确保使用的是最新版本
  2. 手动清理构建缓存:删除项目中的 build 目录和 ohos/.hvigor 目录
  3. 重新运行 flutter run 命令

目前 HarmonyOS 的 Flutter 支持仍在开发阶段,建议关注官方文档获取最新的工具链更新。

回到顶部