欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Android10(Q)系统源码编译

程序员文章站 2024-02-26 21:02:22
...

一 硬件环境

在ubuntu18.04系统中下载编译android10(Q)源码需要如下条件
1,至少4G内存,小于4G内存编译源码期间的等待将会是很痛苦的一件事
2,至少200G硬盘,越大越好
我在编译的过程中使用的是虚拟机,第一次编译分配了150硬盘不够用,最后不得已折腾了三天重装了一次系统分配了500G硬盘才能开始编译,编译期间我查看过硬盘使用情况最高使用了150G硬盘,200G应该够用

二 软件环境

Android10编译需要使用开源的openJDK编译,不能使用oracle的JDK
1,安装openjdk8

sudo add-apt-repository ppa:openjdk-r/ppa
sudo apt-get update
sudo apt-get install openjdk-8-jdk

如果电脑里面存在多个java 版本,则通过如下命令选择openjdk-8即可

sudo update-alternative --config java
sudo update-alternative --config javac

2,安装依赖库

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

3,安装GIT

sudo apt-get install git

4,设置GIT账户

git config --global user.email "[email protected]"
git config --global user.name "xxxxx"

5,安装python

sudo apt-get install python

6,配置PATH环境变量

mkdir ~/bin
echo "PATH=~/bin:\$PATH" >> ~/.bashrc
source ~/.bashrc

7,安装 curl 库,并设置权限

sudo apt-get install curl
curl https://mirrors.tuna.tsinghua.edu.cn/git/git-repo > ~/bin/repo
chmod a+x ~/bin/repo

8,创建工作目录

  mkdir android  //工作目录名字根据自己喜好起
  cd  android

9,添加清华大学镜像源

export REPO_URL='https://mirrors.tuna.tsinghua.edu.cn/git/git-repo/'

10,初始化仓库,并指定要下载android版本

repo init -u https://aosp.tuna.tsinghua.edu.cn/platform/manifest -b android-10.0.0_r10

repo init -u https://aosp.tuna.tsinghua.edu.cn/platform/manifest
或 repo init -u git://aosp.tuna.tsinghua.edu.cn/aosp/platform/manifest
这个默认的下载的是最新的版本
如果提示无法连接到 gerrit.googlesource.com,可以编辑 ~/bin/repo,把 REPO_URL 一行替换成下面的:REPO_URL = ‘https://gerrit-google.tuna.tsinghua.edu.cn/git-repo’
下载特定的版本使用下面的命令
repo init -u https://aosp.tuna.tsinghua.edu.cn/platform/manifest -b android-10.0.0_r10
//-b 后面跟自己要下载的版本号
11, 同步源码

repo sync -j8

接下来就是漫长的等待,时间长短看人品,慢慢等吧,中途如果下载有问题可以 ctrl+c 退出下载再执 行
repo sync 命令直到下载完成,我100M光纤下载android-10.0.0_r10源码用了一晚上八个小时

三 开始编译

1,在源码根目录下执行编译环境脚本

 source build/envsetup.sh

2,执行lunch命令,选择需要编译的版本

lunch

3,开始编译

make -j16

等待编译完成,一般得两到三个小时,取决于机器的配置,编译期间如果 有问题,我相信百度不用我教
4,启动模拟器

emulator &

编译成功后执行此命令可以启动模拟器查看编译后的系统

四 遇到问题

1,libncurses.so.5 和 libtinfo.so.5 找不到

error while loading shared libraries:libncurses.so.5: cannot open shared object file:No such file or directory
error while loading shared libraries: libtinfo.so.5: cannot open shared object file:No such file or directory

库找不到有两种可能,一种就是没有安装(sudo find -name “libncurses.so.5” 在系统根目录下查找),另外一种就是安装了但是没有配置到系统查找路径中。
搜索可以发现在 Android10 源码中就有这两个文件,所以直接建立了两个软连接让系统可以搜索到即可。

sudo ln -s /home/cxp/work/aosp_android0.0.0_r33/prebuilts/gcc/linux-x86/host/x86_64-linux-glibc2.17-4.8/sysroot/usr/lib/libncurses.so.5  /lib/libncurses.so.5
sudo ln -s /home/cxp/work/aosp_android0.0.0_r33/prebuilts/gcc/linux-x86/host/x86_64-linux-glibc2.17-4.8/sysroot/usr/lib/libtinfo.so.5  /lib/libtinfo.so.5

2,api 问题

Killed
-e
******************************
You have tried to change the API from what has been previously approved.

To make these errors go away, you have two choices:
   1. You can add '@hide' javadoc comments to the methods, etc. listed in the
      errors above.

   2. You can update current.txt by executing the following command:
         make system-api-stubs-docs-update-current-api

      To submit the revised current.txt to the main Android repository,
      you will need approval.
******************************

解决办法执行下面的语句,重新编译即可

make system-api-stubs-docs-update-current-api

友情链接:
清华大学开源软件镜像站

声 明:
本文为原创内容欢迎转载,请注明出处,谢谢!