首页 > 其他分享 >harmony_flutter_更新Flutter插件项目结构

harmony_flutter_更新Flutter插件项目结构

时间:2024-12-18 09:46:53浏览次数:7  
标签:插件 default integration harmony ohos test har flutter

更新Flutter插件项目结构

更新内容

  • flutter插件项目中的ohos目录,将从鸿蒙工程project结构,替换为鸿蒙工程module结构。
  • flutter工程中引用的har文件,统一放到 ohos/har 目录下。
  • 更新后需要删除ohos插件中的旧模块目录。

更新步骤

flutter_flutter 中的 integration_test 为例的更新步骤如下

1. integration_test/ohos 目录由 project 结构修改为 module 结构

cd flutter_flutter/packages/integration_test
mv ohos/ohos ./ohos2
rm -rf ohos
mv ohos2 ohos
cd example
flutter pub get
flutter build hap --debug

执行flutter run后会出现报错,需要修改配置文件中的name字段,还需要修改 hvigorfile.ts。

2. 代码更新

2.1 修改 integration_test/ohos/oh-package.json5

修改前:

{
  "name": "ohos",
  "version": "1.0.0",
  "description": "Please describe the basic information.",
  "main": "",
  "author": "",
  "license": "",
  "dependencies": {
  },
  "devDependencies": {
    "@ohos/hypium": "1.0.11"
  }
}

修改后:

{
  "name": "integration_test", // 和插件名(pubspec.yaml中的name)保持一致
  "version": "1.0.0",
  "description": "Please describe the basic information.",
  "main": "",
  "author": "",
  "license": "Apache-2.0",
  "dependencies": {
    "@ohos/flutter_ohos": "file:har/flutter.har",
  }
}

2.2 修改 integration_test/ohos/src/main/module.json5

修改前:

{
  "module": {
    "name": "ohos",
    "type": "har",
    "deviceTypes": [
      "default",
      "tablet",
      "2in1"
    ]
  }
}

修改后:

{
  "module": {
    "name": "integration_test", // 和插件名(pubspec.yaml中的name)保持一致
    "type": "har",
    "deviceTypes": [
      "default",
      "tablet",
      "2in1"
    ]
  }
}

2.3 修改 integration_test/ohos/hvigorfile.ts

修改前:

import { appTasks } from '@ohos/hvigor-ohos-plugin';

export default {
    system: appTasks,  /* Built-in plugin of Hvigor. It cannot be modified. */
    plugins:[]         /* Custom plugin to extend the functionality of Hvigor. */
}

修改后:

export { harTasks } from '@ohos/hvigor-ohos-plugin';

检查是否可以正常运行

  1. 使用 DevEco-Studio 打开 integration_test/example, 配置签名
  2. 使用命令运行example
cd integration_test/example
flutter run -d $DEVICE --debug

运行鸿蒙应用时,需要注意配置文件中 har文件 的引用

引用的har文件在 ohos/har 目录下

integration_test/example/ohos/oh-package.json5

修改后:

{
  // ...
  "dependencies": {
    "@ohos/flutter_ohos": "file:./har/flutter.har"
  },
  "overrides": {
    "@ohos/flutter_ohos": "file:./har/flutter.har"
  }
}

integration_test/example/ohos/entry/oh-package.json5

修改前

{
  // ...
  "dependencies": {
    "@ohos/integration_test": "file:./har/integration_test.har",
  }
}

修改后

{
  // ...
  "dependencies": {
    "integration_test": "file:../har/integration_test.har",
  }
}

可能遇到的问题

1. no such file or directory

日志信息:

hvigor ERROR: ENOENT: no such file or directory, stat 'xxx/flutter_flutter/packages/integration_test/ohos/build/default/cache/default/default@packageHar/ohos/oh_modules/@ohos/flutter_ohos'

解决方案:

手动删除报错信息提示的文件。

日志信息:

hvigor ERROR: ENOENT: operation not permitted, symlink
'xxx/webview_flutter_ohos/ohos/webview_flutter/oh_modules/.ohpm/@ohos+flutter_ohos@file+libs+flutter.har/oh_modules/@ohos/flutter_ohos' -> 
'xxx/webview_flutter_ohos/ohos/build/default/cache/default/default@PackageHar/webview_flutter/oh_modules/@ohos/flutter_ohos'

解决方案:

har结构整改前的部分目录,在更新代码后需要手动删除,例如

  1. flutter_packages/packages/webview_flutter_ohos/ohos/webview_flutter
  2. flutter_packages/packages/path_provider_ohos/ohos/path_provider
  3. flutter_packages/packages/file_selector_ohos/ohos/FileSelector

标签:插件,default,integration,harmony,ohos,test,har,flutter
From: https://www.cnblogs.com/hongmengos/p/18613934

相关文章

  • HarmonyOS鸿蒙开发 - 解决上下两栏白边 - 沉浸式效果
    鸿蒙应用开发从入门到入行预览器上下两栏白边自从HarmonyOS升级到release版后,很多同学会问猫林老师:为什么他的预览器上下有白边,为什么明明根容器写了宽高百分百但没铺满。如下图白边原因其实上面的白边,称之为状态栏。上面会放手机wifi信号、电池电量等信息。一般情况下......
  • 鸿蒙Flutter性能调优分析之帧渲染跟踪
    鸿蒙Flutter性能调优性能分析之帧渲染跟踪Flutter应用进行性能分析时,需利用分析工具捕获应用的trace数据,并对其进行分析。鉴于Flutter应用中可能会出现需要单独追踪某帧渲染的情况,如帧率卡顿或帧丢失,本文特介绍了一种针对单帧追踪的方法。分析工具常用的分析工具包括DevEcoStu......
  • harmony_flutter_videoCompress(视频压缩)
    harmony_flutter_videoCompress(视频压缩)一.MethodChannel1.flutter端代码创建MethodChannel交互通道video_compress接收ohos端传递过来的进度finalcompressProgress$=ObservableBuilder<double>();final_channel=constMethodChannel('video_compress');@......
  • Flutter OHOS flutter_console
    flutter_consoleAFlutterConsoleUI项目介绍一个在Flutter端Console可视化的组件,将ConsoleWindow置于页面最顶层,用于调试,输出日志等。安装使用安装步骤简单Demoimport'package:flutter/material.dart';import'dart:async';import'package:flutter_console/flutter_......
  • harmony_flutter_orientation_plugins(监听屏幕状态插件)
    harmony_flutter_orientation(屏幕旋转)flutter端监听鸿蒙手机得屏幕横竖屏切换等各种状态一.MethodChannel1.flutter端代码创建MethodChannel交互通道接收ohos端传递过来状态classOrientationPlugin{staticconst_methodChannel=constMethodChannel('sos......
  • harmony_flutter_keyboard_visibility(监听动态键盘)
    harmony_flutter_keyboard_visibility(监听动态键盘)一.MethodChannel1.flutter端代码创建StreamBuilder监听event接收ohos端传递过来的状态值finalKeyboardVisibilityController?controller;KeyboardVisibilityControllerget_controller=>controller?......
  • harmony_flutter 实现短信发送
    harmony_flutter实现短信发送ohos端建立通import{FlutterPlugin,FlutterPluginBinding}from'@ohos/flutter_ohos/src/main/ets/embedding/engine/plugins/FlutterPlugin';import{MethodCallHandler,MethodResult}from'@ohos/flutter_ohos/src/main/e......
  • harmony_flutter 实现拨打电话功能
    harmony_flutter实现拨打电话功能ohos端建立通importcallfrom'@ohos.telephony.call';import{FlutterPlugin,FlutterPluginBinding}from'@ohos/flutter_ohos/src/main/ets/embedding/engine/plugins/FlutterPlugin';import{MethodCallHandler,Me......
  • flutter_ohos_原生和flutter交互跳转
    flutter_ohos_原生和flutter交互跳转1.EntryAbility可以继承UIAbilityexportdefaultclassEntryAbilityextendsUIAbilityimplementsExclusiveAppComponent<UIAbility>{detachFromFlutterEngine():void{//thrownewError('Methodnotimplemented.�......
  • flutter_ohos_sequence
    性能分析第一步-梳理线程顺序Flutter应用在性能分析的时候,需要使用分析工具去抓取应用的trace,并对trace进行分析。Flutter应用在渲染流程上与几个线程密不可分,而这篇指南里,主要介绍这几个密不可分的线程,以及它们在渲染流程上顺序。分析工具常用的分析工具有DevEcoStudioProfi......