从零开始Android源码编译(ubuntu 16 AOSP Docker)

1、构建编译环境

写在开头:因为sync源码一直失败,在网上找了别人汇总的各版本源码,步骤参照1.3,在这里直接下载就好

链接: https://pan.baidu.com/s/1yMlHJHJitdI3YvKY2v_AfA 提取码: cigx

从零开始Android源码编译(ubuntu 16 AOSP Docker)_第1张图片
image.png

1.1 虚拟机实现

搭建虚拟机运行环境

这里使用PD虚拟机进行构建的ubuntu 16.04环境

# download
http://mirrors.aliyun.com/ubuntu-releases/16.04/
#安装,配置国内源

1.1.1 环境配置

sudo apt-get install git
git config –global user.email ""
git config –global user.name ""
# https://github.com/mikecriggs/ez-aosp
git clone git://github.com/mikecriggs/ez-aosp.git ez-aosp
cd ez-aosp
./ez-aosp.sh

EZ AOSP is a simple automated and user input driven tool for Ubuntu Linux LTS 16.04+ for an easy setup of an AOSP (Android Open Source Project) build environment.

1.1.2 AOSP build

  • repo
mkdir ~/bin
PATH=~/bin:$PATH
curl https://mirrors.tuna.tsinghua.edu.cn/git/git-repo -o ~/bin/repo   #使用tuna的git-repo镜像
chmod a+x ~/bin/repo
​
vim ~/bin/repo
 # 将这行
 REPO_URL = 'https://gerrit.googlesource.com/git-repo'
 # 改为这行
 REPO_URL = 'https://mirrors.tuna.tsinghua.edu.cn/git/git-repo'
  • Aosp 7.1
mkdir aosp
cd aosp
# repo init -u https://aosp.tuna.tsinghua.edu.cn/platform/manifest
repo init -u https://aosp.tuna.tsinghua.edu.cn/platform/manifest -b android-7.1.2_r36
repo sync

1.2 Docker

docker pull tedwang/aosp-v4:latest

docker search到的应该都是类似的东西,随便jdk版本选择一个pull到本地

Docker门外汉,查看Dockerfile文件应该是直接对ubuntu的公共镜像进行配置,有jdk有g++,可以直接把源码拉过去编译,免去自己配置

# dockerfile一般有以下信息
RUN apt-get update && apt-get install -y  make \
    gcc-arm-linux-gnueabi gcc lib32ncurses5  \
    lib32stdc++6 lib32ncurses5 lib32bz2-1.0 \
    lib32z1 u-boot-tools fakeroot libncurses5-dev \
    python bison flex xsltproc gperf g++ lzma zip \
    libxml2-utils git busybox 
ADD jdk-6u31-linux-x64.bin /usr/java/jdk-6u31-linux-x64.bin
  • 启动镜像

docker run --name='AOSP_New' -it --rm -v ~/Docker/Android/Aosp4:/aosp fanyinmeng/ubuntu14-android4-build-env-docker
-v 本地文件夹:镜像环境文件夹

将下载的源码复制到本地文件夹,在/aosp中查看

2、 编译

  • $ source build/envsetup.sh
root@faf8b93fc475:/aosp/android-4.0.4_r1# source build/envsetup.sh
including device/moto/stingray/vendorsetup.sh
including device/moto/wingray/vendorsetup.sh
including device/samsung/crespo/vendorsetup.sh
including device/samsung/crespo4g/vendorsetup.sh
including device/samsung/maguro/vendorsetup.sh
including device/samsung/toro/vendorsetup.sh
including device/samsung/torospr/vendorsetup.sh
including device/samsung/tuna/vendorsetup.sh
including device/ti/panda/vendorsetup.sh
including sdk/bash_completion/adb.bash
  • $ lunch

编译前对部分文件进行修改(我的环境是 tedwang/aosp-v4:latest + android4.0.4.r1;环境不同会出现各种不同的奇奇怪怪的错误,参见https://blog.csdn.net/zhangwenhaojf40it/article/details/78110106)

make: *** [out/host/linux-x86/obj/EXECUTABLES/obbtool_intermediates/Main.o] Error 1
make: *** Waiting for unfinished jobs....

$ vim build/core/combo/HOST_linux-x86.mk

修改源码目录下/build/core/combo/HOST_linux-x86.mk文件:
将以下语句
HOST_GLOBAL_CFLAGS+= -D_FORTIFY_SOURCE=0
修改为
HOST_GLOBAL_CFLAGS+= -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=0
make: *** [out/host/linux-x86/obj/STATIC_LIBRARIES/libMesa_intermediates/src/glsl/linker.o] Error 1
make: *** Waiting for unfinished jobs....

$ vim external/mesa3d/src/glsl/linker.cpp
Add '#include ' to list of includes
make: *** [out/host/linux-x86/obj/STATIC_LIBRARIES/liboprofile_pp_intermediates/arrange_profiles.o] Error 1
make: *** Waiting for unfinished jobs....

$ vim external/oprofile/libpp/format_output.h
Remove 'mutable' from 'mutable counts_t & counts;' on line 94:
make: *** [out/host/linux-x86/obj/STATIC_LIBRARIES/libgtest_host_intermediates/gtest-all.o] Error 1

$ vim external/gtest/include/gtest/internal/gtest-param-util.h
添加:#include 
make: *** [out/host/linux-x86/obj/EXECUTABLES/test-librsloader_intermediates/test-librsloader] Error 1
make: *** Waiting for unfinished jobs....

$ vim external/llvm/llvm-host-build.mk
add "LOCAL_LDLIBS := -lpthread -ldl"
  • $ make -j4

核心数*2

编译了2天,终于是完成了,各种错误。

从零开始Android源码编译(ubuntu 16 AOSP Docker)_第2张图片
image.png
$ mmm development/tools/idegen/
$ sh ./development/tools/idegen/idegen.sh
获得 android.iml  android.ipr

Tips

命令删除所有以前编译操作的已有输出:

make clobber

Docker环境中中断需要重新执行下列命令,不然会报 not found

$ source build/envsetup.sh
$ lunch 

AOSP Android 源码-

https://www.jianshu.com/p/4a845a65fa8a

从零开始分析AOSP源码(一)——源码下载与编译

https://www.jianshu.com/p/2495c47c2d27

第四章 01 安装部署Android源码编译环境

https://www.youtube.com/watch?v=7TboTftG4ho&t=1326s

你可能感兴趣的:(从零开始Android源码编译(ubuntu 16 AOSP Docker))