Android 源码版本比较多, 这里选择的是 韦东山第四期 Andriod 教程中的 Android-5.0.2, 直接从百问网公开的百度网盘链接下载。由于源码本身已经集成了 Tiny 4412开发板相关配置,省去了很多工作量。
百问网提供配置好编译环境的虚拟机,初步使用了一段时间,诸多不便,这里记录下在Ubuntu 18.04 编译源码的过程。 更方便的是使用Docker安装编译环境,一次配置即可。
编译安卓源码之前,需要安装一些依赖包,最好的方式看官网文档 Establishing a Build Environment ,写的比较详细。
➜ bin java -version
java version "1.7.0_161"
OpenJDK Runtime Environment (IcedTea 2.6.12) (7u161-2.6.12-1)
OpenJDK 64-Bit Server VM (build 24.161-b01, mixed mode)
// 如果安装JDK不是7,编译报错如下:
make -j4
PLATFORM_VERSION_CODENAME=REL
PLATFORM_VERSION=5.0.2
TARGET_PRODUCT=full_tiny4412
TARGET_BUILD_VARIANT=eng
TARGET_BUILD_TYPE=release
TARGET_BUILD_APPS=
TARGET_ARCH=arm
TARGET_ARCH_VARIANT=armv7-a-neon
TARGET_CPU_VARIANT=cortex-a9
TARGET_2ND_ARCH=
TARGET_2ND_ARCH_VARIANT=
TARGET_2ND_CPU_VARIANT=
HOST_ARCH=x86_64
HOST_OS=linux
HOST_OS_EXTRA=Linux-4.4.0-116-generic-x86_64-with-Ubuntu-16.04-xenial
HOST_BUILD_TYPE=release
BUILD_ID=LRX22G
OUT_DIR=out
============================================
Checking build tools versions...
/bin/bash: javac: command not found
************************************************************
You are attempting to build with the incorrect version
of java.
Your version is: openjdk version "1.8.0_151" OpenJDK Runtime Environment (build 1.8.0_151-8u151-b12-0ubuntu0.16.04.2-b12) OpenJDK 64-Bit Server VM (build 25.151-b12, mixed mode).
The required version is: "1.7.x"
Please follow the machine setup instructions at
https://source.android.com/source/initializing.html
************************************************************
build/core/main.mk:167: *** stop. Stop.
#### make failed to build some targets (16 seconds) ####
// 本机 Ubuntu 18.04 安装的依赖项
sudo apt-get install 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 libgl1-mesa-dev libxml2-utils xsltproc unzip
实际编译过程中,有一些编译错误,总结一下,并给出解决方案 。
参考 failed to build aosp. says subcommand failed
解决方案
sudo dpkg --add-architecture i386
sudo apt-get update
sudo apt-get install libc6:i386 libncurses5:i386 libstdc++6:i386
解决方案
sudo apt-get install bison
参考 ubuntu 18.04 编译android 8.1 问题记录
Error when build LineageOS: “make: *** [ninja_wrapper] Error 1”
解决方案
export LC_ALL=C
解决方案
sudo apt-get install libxml2-utils
prebuilts/gcc/linux-x86/host/x86_64-linux-glibc2.11-4.6//x86_64-linux/include/c++/4.6/bits/basic_string.h:270: error: unsupported reloc 43
prebuilts/gcc/linux-x86/host/x86_64-linux-glibc2.11-4.6//x86_64-linux/include/c++/4.6/bits/basic_string.h:270: error: unsupported reloc 43
prebuilts/gcc/linux-x86/host/x86_64-linux-glibc2.11-4.6//x86_64-linux/include/c++/4.6/bits/basic_string.h:235: error: unsupported reloc 43
prebuilts/gcc/linux-x86/host/x86_64-linux-glibc2.11-4.6//x86_64-linux/include/c++/4.6/bits/basic_string.h:235: error: unsupported reloc 43
libnativehelper/JNIHelp.cpp:338: error: unsupported reloc 43
libnativehelper/JniConstants.cpp:89: error: unsupported reloc 43
..............
clang: error: linker command failed with exit code 1 (use -v to see invocation)
build/core/host_shared_library_internal.mk:44: recipe for target 'out/host/linux-x86/obj32/lib/libnativehelper.so' failed
make: *** [out/host/linux-x86/obj32/lib/libnativehelper.so] Error 1
make: *** Waiting for unfinished jobs....
#### make failed to build some targets (46:54 (mm:ss)) ####
参考Android build error on Ubuntu 16.04 LTS 该方法无效
Ubuntu16 编译Android5.1 lollipop 源码出错 unsupported reloc 43 采用该方法解决
解决方案
cp /usr/bin/ld.gold prebuilts/gcc/linux-x86/host/x86_64-linux-glibc2.11-4.6/x86_64-linux/bin/ld
Copying: out/target/common/obj/APPS/Bluetooth_intermediates/noproguard.classes.jar
target SharedLib: libGLES_trace (out/target/product/tiny4412/obj/SHARED_LIBRARIES/libGLES_trace_intermediates/LINKED/libGLES_trace.so)
target SharedLib: libbinder (out/target/product/tiny4412/obj/SHARED_LIBRARIES/libbinder_intermediates/LINKED/libbinder.so)
target Symbolic: libharfbuzz_ng (out/target/product/tiny4412/symbols/system/lib/libharfbuzz_ng.so)
out/target/common/obj/PACKAGING/public_api.txt:20: error 5: Added public field android.Manifest.permission.BACKUP
out/target/common/obj/PACKAGING/public_api.txt:81: error 5: Added public field android.Manifest.permission.INVOKE_CARRIER_SETUP
out/target/common/obj/PACKAGING/public_api.txt:105: error 5: Added public field android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE
out/target/common/obj/PACKAGING/public_api.txt:115: error 5: Added public field android.Manifest.permission.RECEIVE_EMERGENCY_BROADCAST
******************************
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 update-api
To submit the revised current.txt to the main Android repository,
you will need approval.
******************************
build/core/tasks/apicheck.mk:57: recipe for target 'out/target/common/obj/PACKAGING/checkapi-current-timestamp' failed
make: *** [out/target/common/obj/PACKAGING/checkapi-current-timestamp] Error 38
make: *** Waiting for unfinished jobs....
target SharedLib: libbcc (out/target/product/tiny4412/obj/SHARED_LIBRARIES/libbcc_intermediates/LINKED/libbcc.so)
clang: warning: argument unused during compilation: '-nodefaultlibs'
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
#### make failed to build some targets (03:18:04 (hh:mm:ss)) ####
参考[How to fix this API error](make update-api && make -j4make update-api && make -j4make update-api && make -j4)
解决方案
make update-api && make -j4
顺利编译完成,整体编译大约持续4h
Install: out/target/product/tiny4412/system/lib/libwebviewchromium.so
Install: out/target/product/tiny4412/system/app/webview/webview.apk
mkdir -p out/target/product/tiny4412/system/app/webview/lib/arm ;ln -sf /system/lib/libwebviewchromium.so out/target/product/tiny4412/system/app/webview/lib/arm/libwebviewchromium.so
build/tools/generate-notice-files.py out/target/product/tiny4412/obj/NOTICE.txt out/target/product/tiny4412/obj/NOTICE.html "Notices for files contained in the filesystem images in this directory:" out/target/product/tiny4412/obj/NOTICE_FILES/src
Combining NOTICE files into HTML
Combining NOTICE files into text
Installed file list: out/target/product/tiny4412/installed-files.txt
Target system fs image: out/target/product/tiny4412/obj/PACKAGING/systemimage_intermediates/system.img
Running: mkuserimg.sh -s out/target/product/tiny4412/system out/target/product/tiny4412/obj/PACKAGING/systemimage_intermediates/system.img ext4 system 629145600 out/target/product/tiny4412/root/file_contexts
make_ext4fs -s -T -1 -S out/target/product/tiny4412/root/file_contexts -l 629145600 -a system out/target/product/tiny4412/obj/PACKAGING/systemimage_intermediates/system.img out/target/product/tiny4412/system
Creating filesystem with parameters:
Size: 629145600
Block size: 4096
Blocks per group: 32768
Inodes per group: 7680
Inode size: 256
Journal blocks: 2400
Label:
Blocks: 153600
Block groups: 5
Reserved block group size: 39
Created filesystem with 1874/38400 inodes and 136196/153600 blocks
Install system fs image: out/target/product/tiny4412/system.img
out/target/product/tiny4412/system.img+ maxsize=642318336 blocksize=4224 total=549692400 reserve=6488064
#### make completed successfully (39:39 (mm:ss)) ####
编译 u-boot 得到 mkimage 工具,并拷贝到 /usr/bin路径
sudo cp tools/mkimage /usr/bin/