鸿蒙Flutter更新Flutter插件项目布局

打印 上一主题 下一主题

主题 947|帖子 947|积分 2841

更新内容

     

  • flutter插件项目中的ohos目次,将从鸿蒙工程project布局,更换为鸿蒙工程module布局。
  • flutter工程中引用的har文件,统一放到 ohos/har 目次下。
  • 更新后须要删除ohos插件中的旧模块目次。
     更新步骤

     以  flutter_flutter 中的 integration_test 为例的更新步骤如下
     1. integration_test/ohos 目次由 project 布局修改为 module 布局

                                   登录后复制                        
  1. cd flutter_flutter/packages/integration_test
  2. mv ohos/ohos ./ohos2
  3. rm -rf ohos
  4. mv ohos2 ohos
  5. cd example
  6. flutter pub get
  7. flutter build hap --debug
复制代码
      

  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
                       执行flutter run后会出现报错,须要修改设置文件中的name字段,还须要修改 hvigorfile.ts。
     2. 代码更新

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

     修改前:
                                   登录后复制                        
  1. {
  2.   "name": "ohos",
  3.   "version": "1.0.0",
  4.   "description": "Please describe the basic information.",
  5.   "main": "",
  6.   "author": "",
  7.   "license": "",
  8.   "dependencies": {
  9.   },
  10.   "devDependencies": {
  11.     "@ohos/hypium": "1.0.11"
  12.   }
  13. }
复制代码
      

  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
                       修改后:
                                   登录后复制                        
  1. {
  2.   "name": "integration_test", // 和插件名(pubspec.yaml中的name)保持一致
  3.   "version": "1.0.0",
  4.   "description": "Please describe the basic information.",
  5.   "main": "",
  6.   "author": "",
  7.   "license": "Apache-2.0",
  8.   "dependencies": {
  9.     "@ohos/flutter_ohos": "file:har/flutter.har",
  10.   }
  11. }
复制代码
      

  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
                       2.2 修改 integration_test/ohos/src/main/module.json5

     修改前:
                                   登录后复制                        
  1. {
  2.   "module": {
  3.     "name": "ohos",
  4.     "type": "har",
  5.     "deviceTypes": [
  6.       "default",
  7.       "tablet",
  8.       "2in1"
  9.     ]
  10.   }
  11. }
复制代码
      

  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
                       修改后:
                                   登录后复制                        
  1. {
  2.   "module": {
  3.     "name": "integration_test", // 和插件名(pubspec.yaml中的name)保持一致
  4.     "type": "har",
  5.     "deviceTypes": [
  6.       "default",
  7.       "tablet",
  8.       "2in1"
  9.     ]
  10.   }
  11. }
复制代码
      

  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
                       2.3 修改 integration_test/ohos/hvigorfile.ts

     修改前:
                                   登录后复制                        
  1. import { appTasks } from '@ohos/hvigor-ohos-plugin';
  2. export default {
  3.     system: appTasks,  /* Built-in plugin of Hvigor. It cannot be modified. */
  4.     plugins:[]         /* Custom plugin to extend the functionality of Hvigor. */
  5. }
复制代码
      

  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
                       修改后:
                                   登录后复制                        
  1. export { harTasks } from '@ohos/hvigor-ohos-plugin';
复制代码
      

  • 1.
                       查抄是否可以正常运行

     

  • 使用 DevEco-Studio 打开 integration_test/example, 设置签名
  • 使用命令运行example
                                   登录后复制                        
  1. cd integration_test/example
  2. flutter run -d $DEVICE --debug
复制代码
      

  • 1.
  • 2.
                       运行鸿蒙应用时,须要注意设置文件中 har文件 的引用

     引用的har文件在 ohos/har 目次下
     integration_test/example/ohos/oh-package.json5

     修改后:
                                   登录后复制                        
  1. {
  2.   // ...
  3.   "dependencies": {
  4.     "@ohos/flutter_ohos": "file:./har/flutter.har"
  5.   },
  6.   "overrides": {
  7.     "@ohos/flutter_ohos": "file:./har/flutter.har"
  8.   }
  9. }
复制代码
      

  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
                       integration_test/example/ohos/entry/oh-package.json5

     修改前
                                   登录后复制                        
  1. {
  2.   // ...
  3.   "dependencies": {
  4.     "@ohos/integration_test": "file:./har/integration_test.har",
  5.   }
  6. }
复制代码
      

  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
                       修改后
                                   登录后复制                        
  1. {
  2.   // ...
  3.   "dependencies": {
  4.     "integration_test": "file:../har/integration_test.har",
  5.   }
  6. }
复制代码
      

  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
                       可能碰到的问题

     1. no such file or directory

     日志信息:
                                   登录后复制                        
  1. 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'
复制代码
      

  • 1.
                       办理方案:
     手动删除报错信息提示的文件。
     2. operation not permitted, symlink

     日志信息:
                                   登录后复制                        
  1. hvigor ERROR: ENOENT: operation not permitted, symlink
  2. 'xxx/webview_flutter_ohos/ohos/webview_flutter/oh_modules/.ohpm/@ohos+flutter_ohos@file+libs+flutter.har/oh_modules/@ohos/flutter_ohos' ->
  3. 'xxx/webview_flutter_ohos/ohos/build/default/cache/default/default@PackageHar/webview_flutter/oh_modules/@ohos/flutter_ohos'
复制代码
      

  • 1.
  • 2.
  • 3.
                       办理方案:
     har布局整改前的部门目次,在更新代码后须要手动删除,例如
     

  • flutter_packages/packages/webview_flutter_ohos/ohos/webview_flutter
  • flutter_packages/packages/path_provider_ohos/ohos/path_provider
  • flutter_packages/packages/file_selector_ohos/ohos/FileSelector

免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。
回复

使用道具 举报

0 个回复

倒序浏览

快速回复

您需要登录后才可以回帖 登录 or 立即注册

本版积分规则

勿忘初心做自己

金牌会员
这个人很懒什么都没写!

标签云

快速回复 返回顶部 返回列表