未验证 提交 cd6de948 编写于 作者: D duangavin123 提交者: Gitee

update zh-cn/device-dev/quick-start/quickstart-lite-steps-hi3516-application-framework.md.

Signed-off-by: Nduangavin123 <duanxichao@huawei.com>
上级 808f2a90
# 新建应用程序<a name="ZH-CN_TOPIC_0000001171455556"></a> # 编写“Hello World”程序
下方将通过修改源码的方式展示如何编写简单程序,输出“Hello OHOS!”。请在[获取源码](quickstart-lite-sourcecode-acquire.md)章节下载的源码目录中进行下述操作。
1. 新建目录及源码。 下方将展示如何在单板上运行第一个应用程序,其中包括新建应用程序、编译、烧写、运行等步骤,最终输出“Hello World!”。
## 示例目录
示例完整目录如下:
```
applications/sample/hello
│── BUILD.gn
│── include
│ └── helloworld.h
│── src
│ └── helloworld.c
├── bundle.json
│── test
│ └── moduletest
│ └── unittest
productdefine/common
└── products
└── Hi3516DV300.json
```
## 开发步骤
请在源码目录中通过以下步骤创建“Hello World”应用程序:
1. 创建目录,编写业务代码。
新建applications/sample/hello/src/helloworld.c目录及文件,代码如下所示,用户可以自定义修改打印内容(例如:修改World为OH)。其中helloworld.h包含字符串打印函数HelloPrint的声明。当前应用程序可支持标准C及C++的代码开发。
新建**applications/sample/camera/apps/src/helloworld.c**目录及文件,代码如下所示,用户可以自定义修改打印内容(例如:修改OHOS为World)。当前应用程序可支持标准C及C++的代码开发。
``` ```
#include <stdio.h> #include <stdio.h>
#include "helloworld.h"
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
printf("\n************************************************\n"); HelloPrint();
printf("\n\t\tHello OHOS!\n");
printf("\n************************************************\n\n");
return 0; return 0;
} }
void HelloPrint()
{
printf("\n\n");
printf("\n\t\tHello World!\n");
printf("\n\n");
}
``` ```
2. 新建编译组织文件 再添加头文件applications/sample/hello/include/helloworld.h,代码如下所示
新建**applications/sample/camera/apps/BUILD.gn**文件,内容如下所示:
``` ```
import("//build/lite/config/component/lite_component.gni") #ifndef HELLOWORLD_H
lite_component("hello-OHOS") { #define HELLOWORLD_H
features = [ ":helloworld" ] #ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif
#endif
void HelloPrint();
#ifdef __cplusplus
#if __cplusplus
} }
executable("helloworld") { #endif
output_name = "helloworld" #endif
sources = [ "src/helloworld.c" ] #endif // HELLOWORLD_H
include_dirs = [] ```
defines = []
2. 新建编译组织文件。
1. 新建applications/sample/hello/BUILD.gn文件,内容如下所示:
```
import("//build/ohos.gni") # 导入编译模板
ohos_executable("helloworld") { # 可执行模块
sources = [ # 模块源码
"src/helloworld.c"
]
include_dirs = [ # 模块依赖头文件目录
"include"
]
cflags = []
cflags_c = [] cflags_c = []
cflags_cc = []
ldflags = [] ldflags = []
configs = []
deps =[] # 部件内部依赖
part_name = "sample" # 所属部件名称,必选
install_enable = true # 是否默认安装(缺省默认不安装),可选
} }
``` ```
2. 新建applications/sample/bundle.json文件,添加sample部件描述,内容如下所示。
3. 添加新组件。
修改文件**build/lite/components/applications.json**,添加组件hello\_world\_app的配置,如下所示为applications.json文件片段,"\#\#start\#\#"和"\#\#end\#\#"之间为新增配置("\#\#start\#\#"和"\#\#end\#\#"仅用来标识位置,添加完配置后删除这两行):
``` ```
{ {
"components": [ "name": "@ohos/hello",
{ "description": "Hello world example.",
"component": "camera_sample_communication", "version": "3.1",
"description": "Communication related samples.", "license": "Apache License 2.0",
"optional": "true", "publishAs": "code-segment",
"dirs": [ "segment": {
"applications/sample/camera/communication" "destPath": "applications/sample/hello"
],
"targets": [
"//applications/sample/camera/communication:sample"
],
"rom": "",
"ram": "",
"output": [],
"adapted_kernel": [ "liteos_a" ],
"features": [],
"deps": {
"components": [],
"third_party": []
}
}, },
##start## "dirs": {},
{ "scripts": {},
"component": "hello_world_app", "component": {
"description": "Communication related samples.", "name": "hello",
"optional": "true", "subsystem": "applications",
"dirs": [ "syscap": [],
"applications/sample/camera/apps"
],
"targets": [
"//applications/sample/camera/apps:hello-OHOS"
],
"rom": "",
"ram": "",
"output": [],
"adapted_kernel": [ "liteos_a" ],
"features": [], "features": [],
"adapted_system_type": [
"mini",
"small",
"standard"
],
"rom": "10KB",
"ram": "10KB",
"deps": { "deps": {
"components": [], "components": [],
"third_party": [] "third_party": []
}
}, },
##end## "build": {
{ "sub_component": [
"component": "camera_sample_app", "//applications/sample/hello:helloworld"
"description": "Camera related samples.",
"optional": "true",
"dirs": [
"applications/sample/camera/launcher",
"applications/sample/camera/cameraApp",
"applications/sample/camera/setting",
"applications/sample/camera/gallery",
"applications/sample/camera/media"
], ],
"inner_kits": [],
"test": [
"//applications/sample/hello/test:moduletest",
"//applications/sample/hello/test:unittest"
]
}
}
}
``` ```
4. 修改单板配置文件。 bundle.json文件包含两个部分,第一部分说明该子系统的名称,component定义该子系统包含的部件,要添加一个部件,需要把该部件对应的内容添加进component中去。添加的时候需要指明该部件包含的模块sub_component,假如有提供给其它部件的接口,需要在inner_kits中说明,假如有测试用例,需要在test中说明,inner_kits与test没有也可以不添加。
3. 修改产品配置文件。
在productdefine\common\products\Hi3516DV300.json中添加对应的hello部件,直接添加到原有部件后即可。
修改文件**vendor/hisilicon/hispark\_taurus/config.json**,新增hello\_world\_app组件的条目,如下所示代码片段为applications子系统配置,"\#\#start\#\#"和"\#\#end\#\#"之间为新增条目("\#\#start\#\#"和"\#\#end\#\#"仅用来标识位置,添加完配置后删除这两行):
``` ```
{ "usb:usb_manager_native":{},
"subsystem": "applications", "applications:prebuilt_hap":{},
"components": [ "applications:hello":{},
{ "component": "camera_sample_app", "features":[] }, "wpa_supplicant-2.9:wpa_supplicant-2.9":{},
{ "component": "camera_sample_ai", "features":[] },
##start##
{ "component": "hello_world_app", "features":[] },
##end##
{ "component": "camera_screensaver_app", "features":[] }
]
},
``` ```
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册