要求
然后我的ubuntu系统
hinzer@ubuntu:~$ uname -a
Linux ubuntu 5.3.0-42-generic #34~18.04.1-Ubuntu SMP Fri Feb 28 13:42:26 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux
hinzer@ubuntu:~$ free -h
total used free shared buff/cache available
Mem: 19G 1.5G 3.9G 18M 14G 17G
Swap: 2.0G 1.0M 2.0G
hinzer@ubuntu:~$ df -h
Filesystem Size Used Avail Use% Mounted on
udev 9.8G 0 9.8G 0% /dev
tmpfs 2.0G 2.1M 2.0G 1% /run
/dev/sda1 689G 233G 426G 36% /
....
....
配置android开发环境
# 编译所需的工具和相关库
sudo apt-get install openjdk-8-jdk
sudo apt-get install -y 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 ccache libgl1-mesa-dev libxml2-utils xsltproc unzip libssl-dev libssl-dev openssl autoconf m4 libxml2-utils bc libxml-simple-perl
# git和repo工具管理android源码
mkdir ~/bin
PATH=~/bin:$PATH
curl https://storage.googleapis.com/git-repo-downloads/repo > ~/bin/repo
chmod a+x ~/bin/repo
echo 'export PATH=$PATH:~/bin' >> ~/.bashrc
source ~/.bashrc
# 配置git账信息
git config --global user.name "xxx"
git config --global user.email "[email protected]"
# 刷写和调试工具
sudo apt-get install adb -y
sudo apt-get install fastboot -y
sudo apt-get install android-tools-adb
sudo apt-get install android-tools-fastboot
# 配置规则,解决无usb权限问题
sudo touch /etc/udev/rules.d/70-android.rules
sudo vim /etc/udev/rules.d/70-android.rules #添加:SUBSYSTEM=="usb", MODE="0666"
sudo chmod a+rx /etc/udev/rules.d/70-android.rules
sudo service udev restart
下载android源码
由于国内访问google镜像受限,推荐使用清华大学开源镜像站
mkdir -p ~/source/android-10
cd ~/source/android-10
repo init -u https://android.googlesource.com/platform/manifest -b android-10.0.0_r8 # 拉取repo长裤,-u指定远程repo仓库url,-b指定获取特定分支branch
repo sync # 同步代码
要要查看分支列表,请参阅源代码标记和细分版本
编译调试
# 整编源码
source ./build/envsetup.sh # 导出所需环境变量
lunch <product_name> # 选择要编译的product
make -j4 # 开始编译,-j4表示使用4个线程编译
# 运行虚拟机
emulator # 查看系统信息确认是我们刚刚编译的系统