zoukankan      html  css  js  c++  java
  • #2020征文-开发板# 用鸿蒙开发AI应用(四)Helloworld

    目录:

    前言

    环境准备

    第一个程序

    前言
    上一篇,我们把编译和烧录环境都搭建好了,这一篇我们来初探一下鸿蒙OS的应用开发流程。
     #2020征文-开发板# 用鸿蒙开发AI应用(四)Helloworld

    环境准备
    距我们上次搭建环境有段时间了,先来更新一下开发工具和相关开源代码。

    1. 更新 DevEco Device Tools
    在 vscode 里 扩展 -> 从VSIX安装... -> 选择DevEcoDeviceTool-1.0.1.vsix

    #2020征文-开发板# 用鸿蒙开发AI应用(四)Helloworld

    2. 同步代码仓

    cd ~/harmony/openharmony
    repo sync -c

    #2020征文-开发板# 用鸿蒙开发AI应用(四)Helloworld
     

    3. 下载开发工具

    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


    下载应用打包和签名工具。

    第一个程序
    1. 创建程序目录
    在源码 applicationssample 目录下,我们新建一个 myApp 目录放置新增代码。

    2. 创建主程序
    新建主程序 my_first_app.c,简单打印一个Hello World。

    #include <stdio.h>
    #include "los_sample.h"
    
    int main(int argc, char **argv)
    {
        printf("
    ************************************************
    ");
        printf("
    		Hello bluishfish!
    ");
        printf("
    ************************************************
    
    ");
    
        LOS_Sample(g_num);
    
        return 0;
    }


    stdio.h 为标准库,los_sample.h为子程序的头文件。

    3. 创建子程序
    创建子程序los_sample.c, 也是简单打印一下。

    #include <stdio.h>
    
    int g_num = 81;
    void LOS_Sample(int param)
    {
        printf("This is a sample: Param = %d
    ", param);
    }



    在include目录下创建一个头文件los_sample.h

    #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 */


     

    4. 配置BUILD.gn文件
    创建BUILD.gn, 写入配置信息

    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",
        ]
    }


    首先导入 gni 组件,将源码my_first_app.c和los_sample.c编译成my_app_lib库文件,这里指定include为头文件路径。

    然后将my_app_lib打包成 lite_component命名为camera_my_app组件。

    5. 修改 json 配置
    在 buildlite目录下 新建my_hi3516dv300.json

    {
      "ohos_version": "OpenHarmony 1.0",
      "board": "hi3516dv300",
      "kernel": "liteos_a",
      "compiler": "clang",
      "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":""
    }



    将刚才生成的camera_my_app组件,打包为applications应用,放入鸿蒙的子系统中。

    6. 编译
    可以通过ssh登录虚拟机或直接在虚拟机上进行编译,

    #2020征文-开发板# 用鸿蒙开发AI应用(四)Helloworld

    python build.py my_hi3516dv300 -b debug

    注意:一定要带上 debug参数,这样才能启动后才能方便进入OHOS的命令行模式。

    如遇到找不到java路径的情况,是由于新开源代码中加入了应用打包工具引起的,前文已下好工具包,

    #2020征文-开发板# 用鸿蒙开发AI应用(四)Helloworld

    再安装 java即可修复。

    sudo apt install openjdk-11-jre-headless
    java -version

    查看更多章节>>>

    作者:bluishfish

    想了解更多内容,请访问: 51CTO和华为官方战略合作共建的鸿蒙技术社区https://harmonyos.51cto.com/

  • 相关阅读:
    mysql允许远程访问
    ubuntu pip install MySQL-python mysql_config not found
    ubuntu 阿里云源
    V
    KMP算法之next函数解释(大量的反证法 和数学归纳法来袭)
    日常ACM题目
    F
    J
    中缀表达式求值 ,中缀表达转化为后缀表达式求值,
    数据结构
  • 原文地址:https://www.cnblogs.com/HarmonyOS/p/14276307.html
Copyright © 2011-2022 走看看