Docker 编译Android源码

1
2
3
4
5
6
7
8
9
10
It is because there is no package cache in the image, you need to run:

apt-get -qq update
before installing packages, and if your command is in a Dockerfile, you'll then need:

apt-get -qq -y install curl

Always combine RUN apt-get update with apt-get install in the same RUN statement, for example

RUN apt-get update && apt-get install -y package-bar
  • 安装配置openjdk-7-jre
    ubuntu 16 无法安装jdk7解决办法
1
2
3
4
5
6
7
8
9
10
11
12
13
sudo add-apt-repository ppa:openjdk-r/ppa  
sudo apt-get update
sudo apt-get install openjdk-7-jdk

vim/gedit ~/.bashrc
export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64
export JRE_HOME=$JAVA_HOME/jre
export CLASSPATH=.:$JAVA_HOME/lib:$JRE_HOME/lib:$CLASSPATH
export PATH=$PATH:$JAVA_HOME/bin:$JAVA_HOME/bin/tools.jar:$JRE_HOME/bin
export ANDROID_JAVA_HOME=$JAVA_HOME

export USE_CCACHE=1
source ~/.bashrc
  • 安装其他工具
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
dpkg --print-architecture     # 若支持,输出 amd64
dpkg --print-foreign-architectures # 若支持,输出 i386
//手动开启支持
dpkg --add-architecture i386
apt-get update

sudo apt-get install gcc-multilib g++-multilib build-essential
sudo apt-get install git-core gnupg bison flex gperf pngcrush bc zip curl lzop
sudo apt-get install schedtool libxml2 libxml2-utils xsltproc squashfs-tools
sudo apt-get install libesd0-dev libsdl1.2-dev libwxgtk2.8-dev libswitch-perl
sudo apt-get install libssl1.0.0 libssl-dev lib32readline-gplv2-dev libncurses5-dev

cd /AOSP
export USE_CCACHE=1
export CCACHE_DIR=/<path_of_your_choice>/.ccache
prebuilts/misc/linux-x86/ccache/ccache -M 50G
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
26
27
28
29
import xml.dom.minidom  
import os
from subprocess import call

#downloaded source path
rootdir = "E:/androidsource"

#git program path
git = "D:/Git/bin/git.exe"
dom = xml.dom.minidom.parse("E:/androidsource/manifest/default.xml")
root = dom.documentElement

prefix = git + " clone https://aosp.tuna.tsinghua.edu.cn/"
suffix = ".git"

if not os.path.exists(rootdir):
os.mkdir(rootdir)

for node in root.getElementsByTagName("project"):
os.chdir(rootdir)
d = node.getAttribute("path")
last = d.rfind("/")
if last != -1:
d = rootdir + "/" + d[:last]
if not os.path.exists(d):
os.makedirs(d)
os.chdir(d)
cmd = prefix + node.getAttribute("name") + suffix
call(cmd)
  • 出现 curl: (22) The requested URL returned error: 404 Not Found Server does not provide clone.bundle; ignoring. 怎么办?无视即可
  • Linux下载repo
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
mkdir ~/bin
PATH=~/bin:$PATH
curl https://mirrors.tuna.tsinghua.edu.cn/git/git-repo -o repo
(或者下面的地址)
curl https://storage.googleapis.com/git-repo-downloads/repo > repo
chmod a+x repo

repo的运行过程中会尝试访问官方的git源更新自己,
如果想可以使用[tuna的镜像](https://mirrors.tuna.tsinghua.edu.cn/help/git-repo/)源进行更新,
可以将如下内容复制到你的~/.bashrc里
export REPO_URL='https://mirrors.tuna.tsinghua.edu.cn/git/git-repo/'
并重启终端模拟器

cd /AOSP
初始化同步repo
repo init -u https://aosp.tuna.tsinghua.edu.cn/platform/manifest -b android-5.1.1_r9

repo sync -f -j4
AOSP 未下完成是不显示文件,.repo是隐藏文件夹,ctrl+h显示
有问题时删除缓存文件
rm -rf * -R
  • 设置repo环境变量
1
2
3
vim ~/.bashrc
export PATH=~/bin:$PATH
source ~/.bashrc
1
2
3
4
5
docker exec -it 98e0b4f60ec3 bash

$ sudo docker attach 665b4a1e17b6 #by ID or
$ sudo docker attach loving_heisenberg #by Name
$ root@665b4a1e17b6:/#
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
In Window Host:-
1. Create a folder "aosp" -- Window
2. Right Click on "nandan" -- Properties -- sharing -- Advance Sharing
3. Check option "share this folder" - permission -remove Group or Username "Everyone".
4. Add User - select your user account from List
5. Check Full Control,Read,Change
6. Applu- Ok - Exit
7. open cmd - ipconfig - copy ipv4 for Wireless lan Adapter incase if you are using WIFI
----------------
In Ubuntu VM :-
1. Open terminal..
2. become root
$sudo su-
3. apt-cache search cifs
4. if cifs utils not present then install
$ sudo apt-get install cifs-utils
5. df -h
6. $sudo mkdir /media/test
7. $sudo mount.cifs-o username= window_username //window_ip_address/window_share_folder_name /media/test

复制win共享文件夹到Ubuntu
cp -r aosp(win shared folder) AOSP

Android系统源代码的下载与编译

  • 初始化源码所需环境变量和参数

    1
    source build/envsetup.sh
  • lunch 命令选择编译目标

  • make -j16 (nproc 查看cpus)
willkernel wechat
关注微信公众号
帅哥美女们,请赐予我力量吧!