从头搭建Android源码编译环境(Ubuntu 18.04 / 20.04 / 22.04)

在新安装的Ubuntu上(版本20.04LTS),完成搭建Android源码编译环境步骤如下。
顺带说一句,当前用的比较多的Ubuntu是18.04和20.04,在实际项目中一直在用,可用性和稳定性都没问题。
最新的Ubuntu22.04版本,系统默认的二进制库变化比较大,编译Android源码有问题(实测过,没细研究),不如上述2个版本使用起来顺畅。

1. 安装ssh server(可选)

为了方便使用远程终端进行操作和文件传输,通过ssh协议远程使用命令行终端或者winscp等软件进行文件传输。Ubuntu默认没有安装server端软件。
注意:
1)安装后自动运行,无需重启。
2)用当前登录的系统用户就可以通过ssh远程连接。
3)用户必须由密码才可以远程连接。

$ sudo apt install openssh-server

2. 安装net-tools (可选)

安装这个软件包是为了使用ifconfig命令,查看ip等信息。

$ sudo apt install net-tools

3. 安装git

这个都知道是干啥用的

$ sudo apt install git

安装完成后,需要用如下命令进行配置,分别替换为自己的名字和邮箱(不强制真实邮箱)

git config --global user.name YourName
git config --global user.email you@example.com

查看当前git配置:

$ git config -l
user.name=your_name
user.email=your_email
url.ssh://name@url:port/.insteadof=gerrit:
url.ssh://name@url:port/.pushinsteadof=gerrit:
core.repositoryformatversion=0
core.filemode=true
filter.lfs.smudge=git-lfs smudge --skip -- %f
remote.qs.url=gerrit:/platform/sdk
remote.qs.review=gerrit_url
remote.qs.projectname=platform/sdk
remote.qs.fetch=+refs/heads/*:refs/remotes/qs/*

For Ubuntu 22.02 with ssh rsa refer to: Ubuntu 22.04系统git/repo/github/codeup等 无法用ssh方式下载代码问题修复

4. 配置python

Android源码编译中使用默认的python命令,在Ubuntu20.04中安装了python3,需要创建一个连接,让编译脚本可以找到python解释器,否则会报错。
有2种方法(二选一):

1)直接创建一个链接,指向python3

$ sudo ln -s /usr/bin/python3 /usr/bin/python

2)通过update-alternatives工具管理多个版本软件(参考链接)

$ sudo update-alternatives --install /usr/bin/python python /usr/bin/python3 300

3)低版本的Android以来Python 2

需要安装python2.7版本,完成后参照上面的方法设置链接/usr/bin/python,进行后续编译。

$ sudo apt install python2.7
$ sudo update-alternatives --install /usr/bin/python python /usr/bin/python2.7 500

5. 安装编译所需依赖库

这是Ubuntu18.04及后续版本所需的依赖库,如果是之前更老的Ubuntu版本,依赖库会有差异。

5.1 Google原生Android源码编译依赖库

sudo apt-get install git-core gnupg flex bison build-essential zip curl zlib1g-dev gcc-multilib g++-multilib libc6-dev-i386 libncurses5 lib32ncurses5-dev x11proto-core-dev libx11-dev lib32z1-dev libgl1-mesa-dev libxml2-utils xsltproc unzip fontconfig

5.2 高通Qualcom源码依赖库

sudo apt-get install libx11-dev libreadline-dev libgl1-mesa-dev g++-multilib git flex bison gperf build-essential libncurses-dev tofrodos python-markdown libxml2-utils xsltproc zlib1g-dev dpkg-dev libsdl1.2-dev gnupg flex bison gperf build-essential zip curl zlib1g-dev gcc-multilib g++-multilib libc6-dev-i386 lib32ncurses5-dev x11proto-core-dev libx11-dev libgl1-mesa-dev libxml2-utils xsltproc unzip m4 lib32z1-dev ccache libssl-dev

5.3 使用docker运行Ubuntu 20.04,需要单独安装的软件

sudo apt install rsync cpio

5.4 Ubuntu 22.04依赖库

需要单独安装openssl库,默认情况下编译时提示如下错误:

kernel/msm-5.4/scripts/extract-cert.c:21:10: fatal error: 'openssl/bio.h' file not found
#include <openssl/bio.h>
         ^~~~~~~~~~~~~~~
1 error generated.

$ wget https://www.openssl.org/source/openssl-3.0.7.tar.gz
$ tar -xf openssl-3.0.7.tar.gz
$ cd openssl-3.0.7

# 把header安装到/usr/include,.so安装到/usr/lib64,如果指定其他路径,需要配置ld.so.conf
$ ./config --prefix=/usr --openssldir=/usr shared zlib
Configuring OpenSSL version 3.0.7 for target linux-x86_64
Using os-specific seed configuration
Created configdata.pm
Running configdata.pm
Created Makefile.in
Created Makefile

**********************************************************************
***                                                                ***
***   OpenSSL has been successfully configured                     ***
***                                                                ***
***   If you encounter a problem while building, please open an    ***
***   issue on GitHub <https://github.com/openssl/openssl/issues>  ***
***   and include the output from the following command:           ***
***                                                                ***
***       perl configdata.pm --dump                                ***
***                                                                ***
***   (If you are new to OpenSSL, you might want to consult the    ***
***   'Troubleshooting' section in the INSTALL.md file first)      ***
***                                                                ***
**********************************************************************

$ make -j16
$ sudo make install

openssl安装完成后,头文件所在目录:/usr/include/openssl,库文件所在目录:/usr/lib64/

6. 下载Android源码

这里先简要说明一下。如果需要,再单独说明一下通过google官方渠道或者国内镜像进行下载的操作步骤。
Android源码比较多,在公司内网下载,需要20分钟左右的时间;如果是公网,主要看网速及稳定性,几个小时、十几个小时不等。

$ mkdir -p ~/source/android
$ cd ~/source/android

# 以下是下载repo和验证过程
$ export REPO=$(mktemp /tmp/repo.1112222333)
$ curl -o ${REPO} https://storage.googleapis.com/git-repo-downloads/repo
$ gpg --recv-key 8BB9AD793E8E6153AF0F9A4416530D5E920F5C65
$ curl -s https://storage.googleapis.com/git-repo-downloads/repo.asc | gpg --verify - ${REPO} && install -m 755 ${REPO} /usr/local/bin/repo

# 初始化repo
$ repo init -u https://android.googlesource.com/platform/manifest

# 更新代码
# 可用-j参数指定线程数,不能超过服务器端的配置上限
$ repo sync  

7. 安装所需开发工具软件

根据开发需要和个人习惯安装一些工具软件,只列出一些通用的,默认系统没有安装的软件:

1)vim-gtk

带UI的vim,在图形界面下使用方便一点,不用专门开一个终端。

$ sudo apt install vim-gtk

2)vs code

主页:https://code.visualstudio.com/
Ubuntu上dep安装包下载连接:https://code.visualstudio.com/sha/download?build=stable&os=linux-deb-x64
我下载的版本是:code_1.75.0-1675266613_amd64.deb
使用dpkg命令安装:

sudo dpkg -i code_1.75.0-1675266613_amd64.deb

安装后选装需要的extension或者通过登录微软账号自动同步vs code配置。

3)google chrome (或者chromium)

(1) install chrome browser by wget
wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
sudo dpkg -i google-chrome-stable_current_amd64.deb

(2) install chrome browser by ppa
wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | sudo apt-key add
wget -q -O - https://dl.google.com/linux/linux_signing_key.pub | sudo apt-key add -
sudo sh -c ‘echo “deb http://dl.google.com/linux/chrome/deb/ stable main” >> /etc/apt/sources.list.d/google-chrome.list’
sudo apt update
sudo apt install google-chrome

(3) install chromium browser (chromium is open source and can not login google account or sync data)
sudo apt install chromium-browser

4)搜狗输入法,sogou pinyin

(1) download: https://shurufa.sogou.com/linux
(2) Ubuntu安装搜狗输入法

sudo apt-get install fcitx libgsettings-qt1 libqt5qml5 libqt5quick5 libqt5quickwidgets5 qml-module-qtquick2
sudo apt -f install

sudo apt purge ibus

设置fcitx开机自启动
在终端执行sudo cp /usr/share/applications/fcitx.desktop /etc/xdg/autostart/

5)android studio, sdk, ndk

(1) android studio
https://developer.android.google.cn/studio/
https://developer.android.google.cn/studio/preview

(2) ndk
https://developer.android.google.cn/ndk/downloads

6)WPS

https://linux.wps.cn/
https://wps-linux-personal.wpscdn.cn/wps/download/ep/Linux2019/11698/wps-office_11.1.0.11698_amd64.deb
sudo dpkg -i wps-office_11.1.0.11698_amd64.deb

7)WindTerm(或者terminator)

WindTerm download
https://master.dl.sourceforge.net/project/windterm.mirror/2.5.0/WindTerm_2.5.0_Linux_Portable_x86_64.tar.gz?viasf=1

sudo apt install terminator

8)docker

9)Clion

(1) Clion
https://www.jetbrains.com.cn/en-us/clion/download/#section=linux
(2) IntelliJ IDEA Ultimate
https://www.jetbrains.com.cn/idea/download/?section=linux
(3) goland
https://www.jetbrains.com.cn/en-us/go/download/#section=linux
(4) pycharm
https://www.jetbrains.com.cn/en-us/pycharm/download/?section=linux

10)minicom

sudo apt install minicom

minicom安装、配置和使用

dingtalk:
https://page.dingtalk.com/wow/z/dingtalk/simple/ddhomedownload#/

lvm
sudo apt install lvm2

  • 3
    点赞
  • 32
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

抓饼先生

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值