linux 环境 aosp android 源码常见编译错误

3,636 阅读2分钟

ninja: build stopped: subcommand failed

解决办法:

可能部分仓库没同步完整,重新执行:

repo sync -cdj4

如果错误信息中带 KILL 大概率是内存不足导致的,如果是虚拟机可以试试调高RAM,曾经在16G虚拟机上无法运行调高到32G

编译内核时遇到:“error : openssl/bio.h :No such file or folder”

解决方法:

sudo apt install libssl-dev

Exception in thread "main" java.lang.OutOfMemoryError: Java heap space

解决办法:

export _JAVA_OPTIONS="-Xmx4g"

scripts/mod/mk_elfconfig.c fatal error: 'elf.h' file not found

解决办法:

sudo cp -a external/elfutils/libelf/elf.h /usr/local/include

elf.h fatal error: 'features.h' file not found

/usr/local/include/elf.h 文件中去掉 features.h 的引用 include 行

multiple definition of `yylloc'

查看 gcc 版本:

gcc --version

如果是10版本,需要降级到9.3版本

sudo apt-get install gcc-9

sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-9 100

参考:

blog.csdn.net/qq_31175231…

'openssl/bio.h' file not found

brew install openssl

brew link openssl --force

cd /usr/local/include

sudo ln -s /opt/local/include/openssl/ openssl

clang.real: error while loading shared libraries: libncurses.so.5: cannot open shared object file: No such file or directory

sudo apt-get install libncurses5

ninja failed with: exit status 137

export MAVEN_OPTS="-Xms5120m -Xmx5120m"

blog.csdn.net/nei50429373…

如果还不行,增加 swap 分区大小

blog.csdn.net/weixin_4271…

编译的时候使用的线程数不要大于 cpu 核心数,加上 -JN 参数,N 为电脑 cpu 核心数。linux 系统可以通过命令查看 “grep 'core id' /proc/cpuinfo | sort -u | wc -l”,mac 系统通过命令 sysctl -n machdep.cpu.core_count 查看。

You have tried to change the API from what has been previously released in

an SDK. Please fix the errors listed above.

make update-api -j4

prebuilts/gcc/linux-x86/host/x86_64-linux-glibc2.15-4.8//x86_64-linux/bin/ld: error: out/host/linux-x86/obj32/SHARED_LIBRARIES/libart_intermediates/arch/x86/quick_entrypoints_x86.o: unsupported reloc 43 against global symbol art::Runtime::instance_

问题的原因在于aosp中的预编译好的ld程序存在bug,我们使用Ubuntu系统默认的ld来替换它。具体步骤如下:

cd prebuilts/gcc/linux-x86/host/x86_64-linux-glibc2.15-4.8/x86_64-linux/bin
mv ld ld.old 
ln -s /usr/bin/ld.gold ld