preface
In the last article, we set up the compilation and burning environment, this article we will explore the hongmon OS application development process.
Environment to prepare
It has been some time since we last set up the environment. Let’s update the development tools and relevant open source code first.
1. Update DevEco Device Tools
Extension in VScode -> Install from VSIX – > select DevEcoDeviceTool – 1.0.1. Vsix
2. Synchronize the repository
cd ~/harmony/openharmony
repo sync -c
Copy the code
3. Download the development tool
mkdir -p ~/developtools && cd ~/developtools
URL_PREFIX=https://repo.huaweicloud.com/harmonyos/develop_tools/
wget $URL_PREFIX/hapsigntoolv2.jar
wget $URL_PREFIX/hmos_app_packing_tool.jar
Copy the code
Download the application packaging and signing tool.
The first procedure
1. Create a program directory
In the source code applications\sample directory, we create a new myApp directory to put the new code.
2. Create the main program
Create a new main program my_first_app.c and simply print a Hello World.
#include <stdio.h> #include "los_sample.h" int main(int argc, char **argv) { printf("\n************************************************\n"); printf("\n\t\tHello bluishfish! \n"); printf("\n************************************************\n\n"); LOS_Sample(g_num); return 0; }Copy the code
Stdio. h is the standard library, and los_sample.h is the header file of the subroutine.
3. Create a subroutine
Create the subroutine los_sample.c, also a simple print.
#include <stdio.h>
int g_num = 81;
void LOS_Sample(int param)
{
printf("This is a sample: Param = %d\n", param);
}
Copy the code
Create a header file los_sample.h in the include directory
#ifndef _LOS_SAMPLE_H
#define _LOS_SAMPLE_H
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
extern int g_num;
extern void LOS_Sample(int param);
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif /* _LOS_SAMPLE_H */
Copy the code
4. Configure build. gn
Create build. gn and write the configuration information
import("//build/lite/config/component/lite_component.gni")
static_library("my_app_lib") {
sources = [
"my_first_app.c",
"los_sample.c"
]
include_dirs = [
"include",
]
}
lite_component("camera_my_app") {
target_type = "executable"
features = [
":my_app_lib",
]
}
Copy the code
First import the GNI component and compile the source my_first_app.c and los_sample.c into the my_app_lib library file, specifying include as the header file path.
Then package my_app_lib as a lite_Component named camera_my_app component.
5. Modify the JSON configuration
Create a new my_hi3516DV300. json file in the build lite directory
{"ohos_version": "OpenHarmony 1.0", "board": "HI3516DV300 ", "kernel":" LiteOS_A ", "Compiler ":" Clang ", "Subsystem ": companies ", companies" and "subsystem": [ { "name": "applications", "component": [ { "name": "mycamera", "dir": "//applications/sample/camera/myApp:camera_my_app", "features":[] } ] } ], "vendor_adapter_dir": "//vendor/hisi/hi35xx/hi3516dv300/hi3516dv300_adapter", "third_party_dir": "//third_party", "ohos_product_type":"", "ohos_manufacture":"", "ohos_brand":"", "ohos_market_name":"", "ohos_product_series":"", "ohos_product_model":"", "ohos_software_model":"", "ohos_hardware_model":"", "ohos_hardware_profile":"", "ohos_serial":"", "ohos_bootloader_version":"", "ohos_secure_patch_level":"", "ohos_abi_list":"" }Copy the code
Package the camera_my_app component you just generated as applications and place it in Hongmeng’s subsystem.
6. Compile
You can log in to the VM using SSH or compile it directly on the VM.
python build.py my_hi3516dv300 -b debug
Copy the code
Note: Make sure to include the debug parameter so that you can easily access the OHOS command line mode after startup.
If the Java path cannot be found, it is caused by the application packaging tool added to the new open source code, which has been written in the toolkit.
It can be fixed by installing Java again.
sudo apt install openjdk-11-jre-headless
java -version
Copy the code
7. Burning system
After burning in the last section, just select the userfs.img file to burn.
Note that the output directory here is my_HI3516DV300
Click burn and restart the development board.
Run 8.
After burning, we debug under the serial port and connect according to the serial port number assigned by USB
After the development board is started, press Enter to go to the OHOS command line
./bin/camera_my_app
Copy the code
Camera_my_app is the name of the component we defined earlier, and if you can see the output, congratulations on running your first program on the hongmu.
Note the naming correspondence here. In the official example, the source file, library file, component name, and application name are all named in the same way to facilitate project management. But it’s not easy for new people to understand, so I’ve made a distinction here, so I can go through the process a little bit more carefully.
From source code to library, from library to component, from component to application, and finally into OHOS system execution.
Data download
Related documents of this issue can be downloaded on the official account “Deep Awakening”, reply “ohos04” in the background, and get the link.
Next preview
The next article,
We’re going to develop an HAP application with an interface,
And introduce some more component functions,
Stay tuned…