openHarmony南向开发笔记(一)开发环境搭建

openHarmony南向开发笔记(一)开发环境搭建

一、前言

笔者在学习open Harmony开发之前干了一年的STM32、ESP32、CH573等单片机开发。由于工作需要开始学习open Harmony,笔者将通过本系列笔记分享我的学习心得和技巧。

二、电脑配置

  1. 操作系统 – > Ubuntu20.04
  2. 内存 – > 16G SSD – > 500G
  3. CPU – > Intel® Core™ i5-12450H

三、环境搭建

预备工作

  1. 安装虚拟机工具VMware或者VirtualBox。
  2. 新建虚拟机,内存16GB及以上,硬盘100GB及以上。
  3. 安装Ubuntu,推荐使用20.04版本。用户名不能包含中文。
  4. 启动并进入Ubuntu虚拟机,以下步骤将在Ubuntu虚拟机中进行操作。
1、将Shell环境修改为bash
sudo dpkg-reconfigure dash

选择“No”。

在这里插入图片描述

2、替换Ubuntu软件源

在“https://mirrors.ustc.edu.cn/repogen/”下载对应版本最新的源。

#deb cdrom:[Ubuntu 20.04.6 LTS _Focal Fossa_ - Release amd64 (20230316)]/ focal main restricted
# See http:// help.ubuntu.com/community/ UpgradeNotes for how to upgrade to
# newer versions of the distribution.
deb http://cn.archive.ubuntu.com/ubuntu/ focal main restricted
# deb-src http://cn.archive.ubuntu.com/ubuntu/ focal main restricted
## Major bug fix updates produced after the final release of the
# # distribution.
deb http://cn.archive.ubuntu.com/ubuntu/ focal-updates main restricted
# deb-src http:// cn.archive.ubuntu.com/ubuntu/ focal-updates main restricted
## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu
## team. Also, please note that software in universe WILL NOT receive any
## review or updates from the Ubuntu security team.
deb http://cn.archive.ubuntu.com/ubuntu/ focal universe
# deb-src http:// cn.archive.ubuntu.com/ubuntu/ focal universe
deb http://cn.archive.ubuntu.com/ubuntu/ focal-updates universe
# deb-src http:// cn.archive.ubuntu.com/ubuntu/ focal-updates universe
## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu
## team, and may not be under a free licence. Please satisfy yourself as to
## your rights to use the software. Also, please note that software in
## multiverse WILL NOT receive any review or updates from the Ubuntu
## security team.
deb http://cn.archive.ubuntu.com/ubuntu/ focal multiverse
# deb-src http:// cn.archive.ubuntu.com/ubuntu/ focal multiverse
deb http://cn.archive.ubuntu.com/ubuntu/ focal-updates multiverse
# deb-src http:// cn.archive.ubuntu.com/ubuntu/ focal-updates multiverse
## N.B. software from this repository may not have been tested as
## extensively as that contained in the main release, although it includes
# # newer versions of some applications which may provide useful features.
## Also, please note that software in backports WILL NOT receive any review
## or updates from the Ubuntu security team.
deb http://cn.archive.ubuntu.com/ubuntu/ focal-backports main restricted universe multiverse
# deb-src http:// cn.archive.ubuntu.com/ubuntu/ focal-backports main restricted universe multiverse
## Uncomment the following two lines to add software from Canonical's
## 'partner' repository.
## This software is not part of Ubuntu, but is offered by Canonical and the
## respective vendors as a service to Ubuntu users.
# deb http:// archive. canonical. com/ubuntu focal partner
# deb-src http:// archive.canonical.com/ubuntu focal partner
deb http://security.ubuntu.com/ubuntu focal-security main restricted
# deb- src http:// security. ubuntu. com/ubuntu focal-security main restricted
deb http://security.ubuntu.com/ubuntu focal-security universe
# deb- src http:// security. ubuntu. com/ubuntu focal-security universe
deb http://security.ubuntu.com/ubuntu focal-security multiverse
# deb- src http:/ / security. ubuntu. com/ubuntu focal-security multiverse
# This system was installed using small removable media
# (e.g. netinst, live or single CD). The matching "deb cdrom"
# entries were disabled at the end of the installation process.
# For information about how to configure apt package sources,
# see the sources.list(5) manual.

在下载好的文件(sources.list)所在的位置开启一个终端窗口,执行下列命令。

备份原始文件:

sudo cp /etc/apt/sources.list /etc/apt/source.list.bak

替换源:

sudo mv -f sources.list /etc/apt/

更新软件包索引:

sudo apt update
3、安装必要的库和工具

需要分两步进行安装。注意,这里比较重要,官网文档用一步进行安装,会出现问题,导致安装不完整,从而导致后期编译出现“3000”错误。

使用如下apt-get命令安装后续操作所需的库和工具:

sudo apt-get install binutils binutils-dev git git-lfs gnupg flex bison gperf
sudo apt-get install build-essential zip curl zlib1g-dev libc6-dev-i386 lib32ncurses5-dev x11proto-core-dev libx11-dev lib32z1-dev ccache libgl1-mesa-dev libxml2-utils xsltproc
sudo apt-get install unzip m4 bc gnutls-bin python3.8 python3-pip ruby genext2fs device-tree-compiler
sudo apt-get install make libffi-dev e2fsprogs pkg-config perl openssl libssl-dev libelf-dev libdwarf-dev u-boot-tools mtd-utils cpio doxygen liblz4-tool openjdk-8-jre gcc g++ texinfo
sudo apt-get install dosfstools mtools default-jre default-jdk libncurses5 apt-utils wget scons
sudo apt-get install python3.8-distutils tar rsync git-core libxml2-dev lib32z-dev grsync xxd
sudo apt-get install libglib2.0-dev libpixman-1-dev kmod jfsutils reiserfsprogs xfsprogs squashfs-tools pcmciautils quota ppp libtinfo-dev libtinfo5 libncurses5-dev libncursesw5
sudo apt-get install libstdc++6 gcc-arm-none-eabi vim ssh locales libxinerama-dev libxcursor-dev
sudo apt-get install libxrandr-dev libxi-dev
sudo apt-get install gcc-arm-linux-gnueabi gcc-9-arm-linux-gnueabi

将Python 3.8设置为默认Python版本。
查看Python 3.8的位置:

which python3.8

将 Python和 Python3切换 为 Python 3. 8 :

sudo update-alternatives --install /usr/bin/python python {Python 3.8 路径} 1
#{Python 3.8 路径}为上一步查看的Python 3.8的位置
sudo update-alternatives --install /usr/bin/python3 python3 {Python 3.8 路径} 1 
#{Python 3.8 路径}为上一步查看的Python 3.8的位置

将repo添加到环境变量

vim ~/.bashrc               # 编辑环境变量
export PATH=~/bin:$PATH     # 在环境变量的最后添加一行repo路径信息
source ~/.bashrc            # 应用环境变量

获取源码

在Ubuntu环境下通过以下步骤获取OpenHarmony源码。

OpenHarmony发布分支代码获取

OpenHarmony各个版本发布分支的源码获取方式请参考

通过repo + https下载。

repo init -u https://gitee.com/openharmony/manifest.git -b OpenHarmony-4.0-Release --no-repo-verify
repo sync -c
repo forall -c 'git lfs pull'
执行prebuilts

在源码根目录下执行prebuilts脚本,安装编译器及二进制工具。

build/prebuilts_download.sh
编译源码
./build.sh --product-name rk3568 --ccache #./build.sh --product-name rk3568 --target-cpu arm64 --ccache 64位版的编译暂时不要做

或者

./build.sh --product-name rk3568 --ccache --no-prebuilt-sdk #full-sdk
OpenHarmony源码目录结构

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值