• [环境搭建]OpenHarmony开发环境搭建


    1. 开发工具

    1.1 虚拟机

    如果在Windows下开发,需要安装虚拟机。如果本身是Linux环境,可跳过。

    推荐使用VirtualBox。也可以使用VmWare。
    VirtualBox下载地址:https://www.virtualbox.org/wiki/Downloads

    1.2 Ubuntu镜像

    下载地址:https://ubuntu.com/download/desktop

    注:建议使用22.04 LTS及以上版本
    
    • 1

    2 虚拟机安装和配置

    2.1 虚拟机安装

    1. 打开VirtualBox,导入下载的Ubuntu ISO镜像安装
    2. CPU/内存:8核 + 8G(编译吃内存,越大越好)
    3. 磁盘空间预留300GB(OpenHarmony代码仓较大)
    4. 虚拟机中需要安装的软件
    $ sudo apt-get update
    $ sudo apt-get upgrade
    $ sudo apt-get openssh-server
    # 此后,在虚拟机外,可以使用ssh直接访问了(第二个网卡ip地址)
    # SSH工具推荐 WindTerm
    
    • 1
    • 2
    • 3
    • 4
    • 5

    2.2 生成SSH KEY

    参考:
    SSHKEY公钥生成和设置: GITEE

    2.3 配置国内apt源&更新

    # 先备份
    $ sudo cp -a /etc/apt/sources.list /etc/apt/sources.list.bak
    
    # 然后替换
    $ sudo sed -i "s@http://.*archive.ubuntu.com@http://repo.huaweicloud.com@g" /etc/apt/sources.list
    $ sudo sed -i "s@http://.*security.ubuntu.com@http://repo.huaweicloud.com@g" /etc/apt/sources.list
    
    # 更新索引
    $ sudo apt-get update
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9

    2.4 sh修改为bash

    因为部分编译工具链需要bash

    $ sudo dpkg-reconfigure dash   # 对话框中选择no
    # 然后验证
    $ ls -l /bin/sh
    # /bin/sh -> bash
    
    • 1
    • 2
    • 3
    • 4

    2.5 下载OpenHarmony依赖工具

    $ sudo apt-get update && sudo apt-get install binutils git git-lfs gnupg flex bison gperf build-essential zip curl zlib1g-dev gcc-multilib g++-multilib libc6-dev-i386 lib32ncurses5-dev x11proto-core-dev libx11-dev lib32z1-dev ccache libgl1-mesa-dev libxml2-utils xsltproc unzip m4 bc gnutls-bin python3.10 python3-pip ruby
    
    • 1

    2.6 python软链接

    python3.10或者其他版本安装后,增加如下软链接

    $ sudo ln -s /usr/bin/python3.10 /usr/bin/python
    # 验证
    $ ll /usr/bin/python*
    /usr/bin/python -> /usr/bin/python3*
    /usr/bin/python3 -> python3.10*
    /usr/bin/python3.10*
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6

    2.7 samba配置

    为了从Windows直接访问虚拟机中的目录

    1. 安装samba
    $ sudo apt-get install samba
    
    • 1
    1. 配置
    # 添加账号
    $ smbpasswd -a yourname     # 和当前ubuntu登录用户相同,记住密码
    
    # 修改配置文件
    $ sudo vi /etc/samba/smb.conf
    # 在最后一行后加入如下内容
    [yourname]
      comment = yourname's project dir
      path = /home/yourname
      browseable = yes
      writable = yes
      
    # 重启samba,然后可以通过Windows + 虚拟机IP地址来访问
    $ sudo /etc/init.d/smb restart
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14

    3. gitee账号注册

    1. 注册地址
      https://gitee.com/openharmony

    2. 绑定邮箱

    3. 签署开发者原创申明
      https://dco.openharmony.cn/sign-dco

    4. 配置git和Repo

    4.1 git配置

    # 配置账号
    $ git config --global user.name "yourname"    # 和gitee账号名一致
    $ git config --global user.email "youremail@xyz"  # 和gitee注册邮箱一致
    $ git config --global credential.helper store
    
    • 1
    • 2
    • 3
    • 4

    4.2 Repo

    1. 下载码云repo
    # 下载repo,如果有权限问题,使用sudo执行
    $ curl -s https://gitee.com/oschina/repo/raw/fork_flow/repo-py3 > ~/repo
    $ cp ~/repo /usr/local/bin/
    $ chmod a+x /usr/local/bin/repo 
    $ pip3 install -i https://repo.huaweicloud.com/repository/pypi/simple requests
    
    • 1
    • 2
    • 3
    • 4
    • 5
    1. repo下载源码
    $ repo init -u git@gitee.com:openharmony/manifest.git -b master --no-repo-verify
    # 由于网络原因,可能需要多次尝试
    $ repo sync -c
    $ repo forall -c 'git lfs pull'
    
    • 1
    • 2
    • 3
    • 4
    1. 执行prebuilts
    # 在源码根目录下执行脚本,安装编译器及二进制工具。
    $ bash build/prebuilts_download.sh
    
    • 1
    • 2
  • 相关阅读:
    PMP的智慧(2) - 系统性思考及复杂性
    基于SpringBoot+Vue的旅游管理系统
    ToBeWritten之VSOC安全运营
    import javax.validation* 对输入时间 Date 进行校验的注解
    background-repeat
    【Redis】Redis实现分布式锁
    linux逻辑卷扩容和缩减的方法
    人人能读懂redux原理剖析
    小红书直播开启新纪元,拓世法宝AI直播一体机助您轻松成为行业标杆!
    Python网络爬虫4-实战爬取pdf
  • 原文地址:https://blog.csdn.net/superbert/article/details/133797449