当前位置:   article > 正文

Framework开发环境搭建_android framework环境配置

android framework环境配置

Framework开发环境搭建

开启Android Framework之旅,一步步记录自己学习过程。

硬件配置

  • RAM:最低16GB,建议32GB,有条件64GB,内存越高,编译时间越短
  • ROM:最低400GB,代码250GB+构建150GB,建议不低于500GB
  • 64位环境

我自己电脑配置是16G + 1T,算是 满足最低要求,想着无非编译慢点,先搞起来再说。

软件配置

采用 VirtualBox + Ubuntu 的方式。

  • VirtualBox版本: 7.0.8
  • Ubuntu版本:18.04.6 (64-bit)

虚拟机安装时,内存分配了8G + 450G,处理器设置为4核,多了担心主机会卡,运行内存8G不够,增加Swap交换空间来凑,后续会有介绍。

一、软件安装

安装完ubuntu系统后,会带有一些不需要的软件,把用不到的全都卸载掉。

1. 给添加sudo权限

sudo命令用户可能没有权限,使用root权限编辑 /etc/sudoer 中的内容,添加用户sudo权限。

root	ALL=(ALL:ALL) ALL
mx	ALL=(ALL:ALL) ALL
  • 1
  • 2

2. 设置下载镜像源

因为Ubuntu默认的软件仓库地址在国内可能会方便比较慢,甚至会失败的情况,所以下载软件之前需要先设置一下软件仓库镜像源。

使用该指令打开文件

# 
sudo gedit /etc/apt/sources.list
  • 1
  • 2

将下面内容粘贴进去

# 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse

# deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-security main restricted universe multiverse
# # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-security main restricted universe multiverse

deb http://security.ubuntu.com/ubuntu/ bionic-security main restricted universe multiverse
# deb-src http://security.ubuntu.com/ubuntu/ bionic-security main restricted universe multiverse
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13

然后执行

sudo apt-get update
sudo apt-get -f install
sudo apt-get upgrade
  • 1
  • 2
  • 3

3. 环境安装

由于编译Android系统需要安装很多环境,所以我直接将所需要的环境整理成了sh脚本,直接运行该脚本即可。

在Ubuntu里面新建一个env.sh脚本,将以下内容复制进去

#base tools of ubuntu
sudo apt install net-tools gitk tree vim terminator synergy expect minicom cutecom 
#openjdk
sudo apt-get install openjdk-8-jdk 
sudo apt-get install git-core gnupg flex bison gperf build-essential zip curl zlib1g-dev gcc-multilib g++-multilib libc6-dev-i386 lib32ncurses5-dev x11proto-core-dev libx11-dev lib32z-dev libgl1-mesa-dev libxml2-utils xsltproc unzip libc6-dev tofrodos python3-markdown libssl-dev libxml-simple-perl  mingw-w64
#install adb and fastboot
sudo apt-get install android-tools-adb android-tools-fastboot
#install ssh server in order to enable ssh login and scp
sudo apt-get install openssh-server openssh-client
#install python
sudo apt-get install python python-dev python-protobuf protobuf-compiler python-virtualenv python-pip
#install libssl-dev to fix such error "fatal error: openssl/opensslv.h: No such file or directory"
sudo apt-get install libssl-dev
#install audit2allow
sudo apt-get install policycoreutils-python-utils
sudo apt-get install m4
#安装perl环境,否则可能会报错Can't locate XML/Simple.pm in @INC (you may need to install the XML::Simple module)
sudo cpan install XML::Simple
#解决no such file or directory以及Cannot generate supplementary makefiles的问题
sudo apt install lsb
sudo apt-get install lib32stdc++6
sudo apt-get install ia32-libs
sudo apt-get install lib32ncurses5
sudo apt-get install lib32z1
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24

给该脚本设置执行权限,之后执行即可

sudo chmod 777 env.sh 
  • 1

4. 增加swap空间大小

  • 查看本机swap交换空间的内存大小
free -m
  • 1

在这里插入图片描述
可以看到内存为8G,我本地扩大到了32G的虚拟内存,默认swap大小是2G的。

  • 创建Swap文件
$ sudo -i
# 输入密码后,切换root。
$ mkdir /swap
# 建立swap文件夹
$ cd /swap/
# 进入到swap文件夹
$ sudo dd if=/dev/zero of=swapfile bs=32M count=1k
# 建立swapfile,大小为bs*count = 32M * 1k = 32G

#将生成的文件转换为Swap文件
$ sudo mkswap -f swapfile


# 最后激活swap文件
$ sudo swapon swapfile
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15

使用 $ free -m 查看内存是否扩展成功。

设置为永久swap,否则重启后失效。

# 执行 
sudo gedit /etc/fstab

#将下列内容 复制到文件的后面,保存即可
/swap/swapfile                                 swap            swap    sw              0       0
  • 1
  • 2
  • 3
  • 4
  • 5

二、源码下载

1. 安装repo

Android源码同时使用git和repo进行管理,repo是基于git的代码管理工具,类似github、gitee,所以需要同时安装git和repo。

执行

sudo apt-get update
sudo apt-get install repo
  • 1
  • 2

安装完之后 执行

repo verison
  • 1

如果提示,repo command not found 说明没安装成功。
需要接着操作:

# 1.先创建个文件夹,隐藏的
sudo mkdir ~/.bin
# 设置下权限
sudo chmod 777 ~/.bin

# 2.环境变量配置一下
PATH=~/bin:$PATH

# 3.使用镜像下载repo

 #使用清华大学镜像
sudo curl https://mirrors.tuna.tsinghua.edu.cn/git/git-repo > ~/.bin/repo

chmod a+x ~/bin/repo

# 将repo配置到环境变量
sudo gedit ~/.bashrc

# 在.bashrc文件末添加下面的内容保存退出
# repo
alias repo="~/.bin/repo"

# 4.同步文件变化
source .bashrc
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24

再次执行

repo verison
# 出现下面提示,则安装成功了
<repo not installed>
repo launcher version 2.15
(from /usr/bin/repo)
  • 1
  • 2
  • 3
  • 4
  • 5

2. 源码下载

创建一个放置源码的目录asop。

# 1.创建目录
mkdir aosp
cd aosp
export REPO_URL='https://mirrors.tuna.tsinghua.edu.cn/git/git-repo/' 
# 2. 设置git用户名、邮箱
git config --global user.email “usergmail@gmail.com”
git config --global user.name “username”

# 3.初始化仓库,并设置下载的源码版本为安卓9
repo init -u https://mirrors.tuna.tsinghua.edu.cn/git/AOSP/platform/manifest -b android-9.0.0_r8


# 4.~/aosp/.repo$ 中查看 manifest.xml指定的下载url,如果指的是
<manifest>
  <include name="default.xml" />
</manifest>

# 打开目录manifest,查看default.xml,将下载url替换成清华的镜像 https://mirrors.tuna.tsinghua.edu.cn/git/AOSP/platform/manifest
<remote  name="aosp"
           fetch=".."
           review="https://mirrors.tuna.tsinghua.edu.cn/git/AOSP/platform/manifest" />
  <default revision="refs/tags/android-9.0.0_r8"
           remote="aosp"
           sync-j="4" />
           ...
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25

之后执行

#同步源码
repo sync
  • 1
  • 2

静静地等待下载,直到下载完成,提示
repo sync has finished successfully。

下载完成之后,方可看到完整的目录:
Android 源码目录

3. 编译源码

  • 构建所需要的环境
source build/envsetup.sh
  • 1
  • 选择构建的目标版本
lunch
  • 1

执行完lunch会列出所有的目标版本,我这边显示50个。
在这里插入图片描述
不同的目标版本对应的设备也不同,因为不同的设备硬件配置也不一样,比如有的设备处理器架构是x86的,有的是arm64的,我选了第6个。
最后开始编译
执行

m
  • 1

我没有设置线程数,默认自动配置。之后就是等待它编译完成。
在这里插入图片描述

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小丑西瓜9/article/detail/129212
推荐阅读
相关标签
  

闽ICP备14008679号