当前位置:   article > 正文

鸿蒙应用开发初尝试《创建项目》,之前那篇hello world作废_file 'd:/myharmonyos/entry/src/main/ets/view/home.

file 'd:/myharmonyos/entry/src/main/ets/view/home.ets' is not a module.

经过几年的迅速发展,鸿蒙抛弃了JAVA写应用的方式,几年前了解的鸿蒙显然就gg了。

这几年鸿蒙发布了方舟(ArkUI Arkts),将TypeScript作为了推荐开发语言,你依然可以用FA+JS,但华为推荐用Stage+ArkTs!!!那么你还是用Stage+ArkTs开发吧!!

采用Mac

第一步下载IDEA

HUAWEI DevEco Studio和SDK下载和升级 | HarmonyOS开发者

安装配置

省略安装后启动.....

当你要创建第一个项目的时候会弹出下面这个,我这里已经把node ohpm全部安装好了就全是√。

如果没安装画红框的地方会出现蓝色字,点击安装或选择安装位置就可以

创建项目

点击Finish项目就创建成功了!!

项目目录展示说明

按照Ohos来说,华为把项目化分了包。实际位置可能不在同级目录。

ets/entryability项目目录是华为“约定”存放ablility window的地方

ets/pages 项目目录是华为“约定”存放页面内容(组件)的地方

当然你不一定放要放,可以自己新建包名,ability在配置文件module.json5链接好就行 page在显示的时候对应上包名就可以。

entry/configuration 存放就是配置信息

项目文件说明

AppScope/app.json5文件 很显然包括了app的包名,版本,应用名(lable)等信息

  1. {
  2. "app": {
  3. "bundleName": "com.lyl.hello",
  4. "vendor": "lyl",
  5. "versionCode": 1000000,
  6. "versionName": "1.0.0",
  7. "icon": "$media:app_icon",
  8. "label": "$string:app_name"
  9. }
  10. }

entry/configuration/build-profile.json5  api类型等信息

  1. {
  2. "apiType": 'stageMode',
  3. "buildOption": {
  4. },
  5. "targets": [
  6. {
  7. "name": "default",
  8. "runtimeOS": "HarmonyOS"
  9. },
  10. {
  11. "name": "ohosTest",
  12. }
  13. ]
  14. }

entry/configuration/hvigorfile.ts 构建器脚本 暂时不能修改就不列了

entry/configuration/module.json5 类manifest文件写法不同内容不一样

  1. {
  2. "module": {
  3. "name": "entry",
  4. "type": "entry",
  5. "description": "$string:module_desc",
  6. "mainElement": "EntryAbility",
  7. "deviceTypes": [
  8. "phone",
  9. "tablet"
  10. ],
  11. "deliveryWithInstall": true,
  12. "installationFree": false,
  13. "pages": "$profile:main_pages",
  14. "abilities": [
  15. {
  16. "name": "EntryAbility",
  17. "srcEntry": "./ets/entryability/EntryAbility.ts",
  18. "description": "$string:EntryAbility_desc",
  19. "icon": "$media:icon",
  20. "label": "$string:EntryAbility_label",
  21. "startWindowIcon": "$media:icon",
  22. "startWindowBackground": "$color:start_window_background",
  23. "exported": true,
  24. "skills": [
  25. {
  26. "entities": [
  27. "entity.system.home"
  28. ],
  29. "actions": [
  30. "action.system.home"
  31. ]
  32. }
  33. ]
  34. }
  35. ]
  36. }
  37. }

entry/configuration/oh-package.json5 相当于安卓项目模块(app)下面build.gradle文件

  1. {
  2. "name": "entry",
  3. "version": "1.0.0",
  4. "description": "Please describe the basic information.",
  5. "main": "",
  6. "author": "",
  7. "license": "",
  8. "dependencies": {}
  9. }

configuration/build-profile.json5 模块信息,编译api版本等

  1. {
  2. "app": {
  3. "signingConfigs": [],
  4. "compileSdkVersion": 9,
  5. "compatibleSdkVersion": 9,
  6. "products": [
  7. {
  8. "name": "default",
  9. "signingConfig": "default",
  10. }
  11. ]
  12. },
  13. "modules": [
  14. {
  15. "name": "entry",
  16. "srcPath": "./entry",
  17. "targets": [
  18. {
  19. "name": "default",
  20. "applyToProducts": [
  21. "default"
  22. ]
  23. }
  24. ]
  25. }
  26. ]
  27. }

configuration/oh-package.json5相当于安卓项目中project层的build.gradle

  1. {
  2. "name": "hello",
  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.6"
  12. }
  13. }

configuration/oh-package.json5自动生成的不用直接改

page/index 一种响应式编程组件写法。“状态变更,重新渲染”

  1. @Entry
  2. @Component
  3. struct Index {
  4. @State message: string = 'Hello World'
  5. build() {
  6. Row() {
  7. Column() {
  8. Text(this.message)
  9. .fontSize(50)
  10. .fontWeight(FontWeight.Bold)
  11. }
  12. .width('100%')
  13. }
  14. .height('100%')
  15. }
  16. }

运行项目

连接鸿蒙手机(注意api版本9就需要3.1的鸿蒙系统才能运行成功到真机)

总结

通过创建项目大致了解了项目结构、文件内容,了解了华为用到技术,与自己懂的相应证,就知道要进一步了解哪些知识了。

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小小林熬夜学编程/article/detail/315469
推荐阅读
相关标签