首先最好编译的是Android Emulator,应为开发android emulator的人大部分在mac上工作,所以编译起来还是比较简单
mkdir ~/bin PATH=~/bin:$PATH curl https://storage.googleapis.com/git-repo-downloads/repo > ~/bin/repo
chmod a+x ~/bin/repo
export REPO_URL= https://gerrit-googlesource.proxy.ustclug.org/git-repo
1 下载
cd WORKDIR
repo init -u git://mirrors.ustc.edu.cn/aosp/platform/manifest
repo init -b emu-master-dev
repo sync -d -j4 --no-tags
如何查看有哪些模拟器分之? repo init完成后会出现.repo目录。执行如下命令查看emu分支
cd .repo/manifests
git branch -r | grep emu
切分支就适用命令repo init -b ${分支名称}
2 编译
cd external/qemu
./android/configure.sh
./android/rebuild.sh --debug --verbose
基本上编译不会遇到错误,编译产生的目标文件在external/qemu/objs下面
2 AOSP
1 要安装 gnupg
brew install gnupg2
2 坑: xcode版本8.33 macos.sdk = 11
1 java 版本 jdk8 > jdk8u100
aosp 代码的下载和上面模拟器下载是一样的 ,只不过分支不同
但是编译起来很坑爹,需要下载java比较高版本的jdk,搜则有一个javac的bug导致编译失败
2 Makos Sdk
需要下载合适的macos sdk,下载地址
https://github.com/phracker/MacOSX-SDKs/releases, 注意读一下readme,上面有介绍怎么安装
3 jack oom问题
export JACK_SERVER_VM_ARGUMENTS="-Dfile.encoding=UTF-8 -XX:+TieredCompilation -Xmx4g"
./prebuilts/sdk/tools/jack-admin kill-server
./prebuilts/sdk/tools/jack-admin start-server
4 bison
cd external/bison
git cherry-pick 1d51d548fc09bfa6bbede72fa7b231dfc0eab275
然后适用编译出来的bison替换prebuild的bison
下载
git clone https://aosp.tuna.tsinghua.edu.cn/kernel/goldfish.git
git branch -r
git checkout android-goldfish-4.14-dev
最坑的就是这个
安装elf openssl, gawk gxargs gsed
brew install libelf
cp /usr/local/Cellar/libelf/0.8.13_1/include/libelf /usr/local/include/libelf
brew install openssl
cp /usr/local/Cellar/openssl/1.0.2s/include/openssl /usr/local/include/openssl
brew install gawk
cp /usr/local/bin/gawk /usr/local/bin/awk
brew install findutils
cp /usr/local/bin/gxargs cp /usr/local/bin/xargs
brew install gnu-sed
cp /usr/local/gsed /usr/local/sed
2 编译
${AOSP_WORKDIR}/prebuilts/qemu-kernel/build-kernel.sh --arch=x86_64 --config=x86_64_ranchu --verbose
我遇到的一个问题就是快要编译成功的时候提示
empty (sub)expressionmake[2]: *** [arch/x86/boot/compressed/vmlinux.relocs] Error 1
make[1]: *** [arch/x86/boot/compressed/vmlinux] Error 2
make: *** [bzImage] Error 2
Could not build the kernel. Aborting !
引起问题的是arch/x86/tools/relocs vmlinux > arch/x86/boot/compressed/vmlinux.relocs;arch/x86/tools/relocs --abs-relocs vmlinux 这句命令
这其实还是gnu 的库和mac库的不兼容引起的
其中有这样一段代码,在arch/x86/tools/relocs.c文件中
[S_REL] =
"^(__init_(begin|end)|"
"__x86_cpu_dev_(start|end)|"
"(__parainstructions|__alt_instructions)(|_end)|"
"(__iommu_table|__apicdrivers|__smp_locks)(|_end)|"
"__(start|end)_pci_.*|"
"__(start|end)_builtin_fw|"
"__(start|stop)___ksymtab(|_gpl|_unused|_unused_gpl|_gpl_future)|"
"__(start|stop)___kcrctab(|_gpl|_unused|_unused_gpl|_gpl_future)|"
"__(start|stop)___param|"
"__(start|stop)___modver|"
"__(start|stop)___bug_table|"
"__tracedata_(start|end)|"
"__(start|stop)_notes|"
"__end_rodata|"
"__initramfs_start|"
"(jiffies|jiffies_64)|"
#if ELF_BITS == 64
"__per_cpu_load|"
"init_per_cpu__.*|"
"__end_rodata_hpage_align|"
#endif
"__vvar_page|"
"_end)$"
改成如下
/*
* These symbols are known to be relative, even if the linker marks them
* as absolute (typically defined outside any section in the linker script.)
*/
[S_REL] =
"^(__init_(begin|end)|"
"__x86_cpu_dev_(start|end)|"
"(__parainstructions|__alt_instructions)(_end)?|"
"(__iommu_table|__apicdrivers|__smp_locks)(_end)?|"
"__(start|end)_pci_.*|"
"__(start|end)_builtin_fw|"
"__(start|stop)___ksymtab(_gpl|_unused|_unused_gpl|_gpl_future)?|"
"__(start|stop)___kcrctab(_gpl|_unused|_unused_gpl|_gpl_future)?|"
"__(start|stop)___param|"
"__(start|stop)___modver|"
"__(start|stop)___bug_table|"
"__tracedata_(start|end)|"
"__(start|stop)_notes|"
"__end_rodata|"
"__initramfs_start|"
"(jiffies|jiffies_64)|"
#if ELF_BITS == 64
"__per_cpu_load|"
"init_per_cpu__.*|"
"__end_rodata_hpage_align|"
#endif
"__vvar_page|"
"_end)$"
具体为什么自己研究去吧 ,我要提patch给内核了