Ubuntu18.04编译android9.0实践

背景

编译android的源码有很多的价值。
1 自己手头有最全的代码,不用去网站上做源码搜索工作。
2 学习源码。
3 代码设计实现适配源码框架结构。

环境

使用的Ubuntu18.04,编译Android P(Android9.0)源码。goog渠道下载源码太慢,使用了清华的镜像,P源码的size达到了120G,包括编译生成的size预测接近100G,因此一共给P源码文件预留了250G的size。

依赖安装

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

安装过程中libesd0-dev安装失败,修改安装源文件

vim /etc/apt/sources.list
#for install libesd0-dev in aosp build
deb http://us.archive.ubuntu.com/ubuntu/ xenial main universe
deb-src http://us.archive.ubuntu.com/ubuntu/ xenial main universe

# 保存后执行下面几行
sudo apt-get update
sudo apt-get install libesd0-dev

JDK

可配置的Android Studio安装目录下的路径:xxx/androidstudio/jre/

开始编译

直接make
出于学习目的,没有配置直接编译的,输出默认的genric。
漫长等待…

问题

[run_soong_ui] Error 1

这个错误会有很多的原因,列出其中一个具体问题和解决方法。
错误:

[  0% 1/56523] //external/libpng:libpng link libpng.so [linux_glibc]
FAILED: out/soong/.intermediates/external/libpng/libpng/linux_glibc_x86_64_shared/libpng.so 
prebuilts/clang/host/linux-x86/clang-4691093/bin/clang++  @out/soong/.intermediates/external/libpng/libpng/linux_glibc_x86_64_shared/libpng.so.rsp out/soong/.intermediates/external/compiler-rt/libcompiler_rt-extras/linux_glibc_x86_64_static/libcompiler_rt-extras.a out/soong/.intermediates/external/zlib/libz/linux_glibc_x86_64_shared/libz-host.so out/soong/.intermediates/external/libcxx/libc++/linux_glibc_x86_64_shared/libc++.so  -o out/soong/.intermediates/external/libpng/libpng/linux_glibc_x86_64_shared/libpng.so -shared -Wl,-soname,libpng.so -target x86_64-linux-gnu -Bprebuilts/gcc/linux-x86/host/x86_64-linux-glibc2.15-4.8/x86_64-linux/bin  -Wl,--no-undefined -Wl,-z,noexecstack -Wl,-z,relro -Wl,-z,now -Wl,--no-undefined-version --gcc-toolchain=prebuilts/gcc/linux-x86/host/x86_64-linux-glibc2.15-4.8 --sysroot prebuilts/gcc/linux-x86/host/x86_64-linux-glibc2.15-4.8/sysroot -m64 -Bprebuilts/gcc/linux-x86/host/x86_64-linux-glibc2.15-4.8/lib/gcc/x86_64-linux/4.8 -Lprebuilts/gcc/linux-x86/host/x86_64-linux-glibc2.15-4.8/lib/gcc/x86_64-linux/4.8 -Lprebuilts/gcc/linux-x86/host/x86_64-linux-glibc2.15-4.8/x86_64-linux/lib64 -ldl -lpthread -lm -lrt -Wl,-rpath,\$ORIGIN/../lib64 -Wl,-rpath,\$ORIGIN/lib64  -nodefaultlibs -lgcc_s -lgcc -lc -lgcc_s -lgcc
prebuilts/gcc/linux-x86/host/x86_64-linux-glibc2.15-4.8/x86_64-linux/bin/ld: error: out/soong/.intermediates/external/libpng/libpng/linux_glibc_x86_64_static/obj/external/libpng/png.o: file is empty
prebuilts/gcc/linux-x86/host/x86_64-linux-glibc2.15-4.8/x86_64-linux/bin/ld: error: out/soong/.intermediates/external/libpng/libpng/linux_glibc_x86_64_static/obj/external/libpng/pngerror.o: file is empty
prebuilts/gcc/linux-x86/host/x86_64-linux-glibc2.15-4.8/x86_64-linux/bin/ld: error: out/soong/.intermediates/external/libpng/libpng/linux_glibc_x86_64_static/obj/external/libpng/pngget.o: file is empty
prebuilts/gcc/linux-x86/host/x86_64-linux-glibc2.15-4.8/x86_64-linux/bin/ld: error: out/soong/.intermediates/external/libpng/libpng/linux_glibc_x86_64_static/obj/external/libpng/pngmem.o: file is empty
prebuilts/gcc/linux-x86/host/x86_64-linux-glibc2.15-4.8/x86_64-linux/bin/ld: error: out/soong/.intermediates/external/libpng/libpng/linux_glibc_x86_64_static/obj/external/libpng/pngpread.o: file is empty
prebuilts/gcc/linux-x86/host/x86_64-linux-glibc2.15-4.8/x86_64-linux/bin/ld: error: out/soong/.intermediates/external/libpng/libpng/linux_glibc_x86_64_static/obj/external/libpng/pngread.o: file is empty
prebuilts/gcc/linux-x86/host/x86_64-linux-glibc2.15-4.8/x86_64-linux/bin/ld: error: out/soong/.intermediates/external/libpng/libpng/linux_glibc_x86_64_static/obj/external/libpng/pngrio.o: file is empty
prebuilts/gcc/linux-x86/host/x86_64-linux-glibc2.15-4.8/x86_64-linux/bin/ld: error: out/soong/.intermediates/external/libpng/libpng/linux_glibc_x86_64_static/obj/external/libpng/pngrtran.o: file is empty
prebuilts/gcc/linux-x86/host/x86_64-linux-glibc2.15-4.8/x86_64-linux/bin/ld: error: out/soong/.intermediates/external/libpng/libpng/linux_glibc_x86_64_static/obj/external/libpng/pngrutil.o: file is empty
prebuilts/gcc/linux-x86/host/x86_64-linux-glibc2.15-4.8/x86_64-linux/bin/ld: error: out/soong/.intermediates/external/libpng/libpng/linux_glibc_x86_64_static/obj/external/libpng/pngset.o: file is empty
prebuilts/gcc/linux-x86/host/x86_64-linux-glibc2.15-4.8/x86_64-linux/bin/ld: error: out/soong/.intermediates/external/libpng/libpng/linux_glibc_x86_64_static/obj/external/libpng/pngtrans.o: file is empty
prebuilts/gcc/linux-x86/host/x86_64-linux-glibc2.15-4.8/x86_64-linux/bin/ld: error: out/soong/.intermediates/external/libpng/libpng/linux_glibc_x86_64_static/obj/external/libpng/pngwio.o: file is empty
prebuilts/gcc/linux-x86/host/x86_64-linux-glibc2.15-4.8/x86_64-linux/bin/ld: error: out/soong/.intermediates/external/libpng/libpng/linux_glibc_x86_64_static/obj/external/libpng/pngwrite.o: file is empty
prebuilts/gcc/linux-x86/host/x86_64-linux-glibc2.15-4.8/x86_64-linux/bin/ld: error: out/soong/.intermediates/external/libpng/libpng/linux_glibc_x86_64_static/obj/external/libpng/pngwtran.o: file is empty
prebuilts/gcc/linux-x86/host/x86_64-linux-glibc2.15-4.8/x86_64-linux/bin/ld: error: out/soong/.intermediates/external/libpng/libpng/linux_glibc_x86_64_static/obj/external/libpng/pngwutil.o: file is empty
prebuilts/gcc/linux-x86/host/x86_64-linux-glibc2.15-4.8/x86_64-linux/bin/ld: error: out/soong/.intermediates/external/libpng/libpng/linux_glibc_x86_64_static/obj/external/libpng/intel/intel_init.o: file is empty
prebuilts/gcc/linux-x86/host/x86_64-linux-glibc2.15-4.8/x86_64-linux/bin/ld: error: out/soong/.intermediates/external/libpng/libpng/linux_glibc_x86_64_static/obj/external/libpng/intel/filter_sse2_intrinsics.o: file is empty
clang-6.0: error: linker command failed with exit code 1 (use -v to see invocation)
ninja: build stopped: subcommand failed.
10:50:07 ninja failed with: exit status 1
build/make/core/main.mk:21: recipe for target 'run_soong_ui' failed
make: *** [run_soong_ui] Error 1

解决:
添加环境变量

vim .bashrc

# 在文件中添加
#aosp setup
export PATH=~/bin:$PATH
export USE_CCACHE=1
export LC_ALL=C

#保存文件后,执行下面一行
source .bashrc

error:VNDK library: libpower’s ABI has EXTENDING CHANGES

解决

vim build/make/target/board/genric/BoardConfig.mk

# 找到下面一行
BOARD_VNDK_VERSION := current
# 去掉current,变为
BOARD_VNDK_VERSION :=
# 接着在这行后面添加下面一行
BOARD_VNDK_RUNTIME_DISABLE := true

结束

解决问题后输入make编译从头开始编译,但编译器会计算略过已经编译好的文件。
遇到问题google。

你可能感兴趣的:(Android)