Ubuntu 18.04 编译 Android 5.0 注意事项

Ubuntu 18.04 编译 Android 5.0 注意事项


最近新安装了Ubuntu 18.04,本篇文章记录一下编译 Android 5.0 过程中遇到的问题和解决办法。

安装JDK7

Android 5 要求OpenJDK版本7,安装过程可参考: https://askubuntu.com/questions/761127/how-do-i-install-openjdk-7-on-ubuntu-16-04-or-higher

报错一

flex-2.5.39: loadlocale.c:130: _nl_intern_locale_data: Assertion `cnt < (sizeof (_nl_value_type_LC_TIME) / sizeof (_nl_value_type_LC_TIME[0]))' failed."

编译前在环境变量中加入:

export LC_ALL=C

报错二

... error: unsupported reloc 43: ...

在 build/core/clang/HOST_x86_common.mk 文件中找到:

CLANG_CONFIG_x86_LINUX_HOST_EXTRA_ASFLAGS

在其后添加代码行:

-B$($(clang_2nd_arch_prefix)HOST_TOOLCHAIN_FOR_CLANG)/x86_64-linux/bin

此错误可参考以下内容:
https://stackoverflow.com/questions/36048358/building-android-from-sources-unsupported-reloc-43
https://android-review.googlesource.com/c/platform/build/+/223100/1/core/clang/HOST_x86_common.mk
http://oopsmonk.github.io/blog/2016/06/07/android-build-error-on-ubuntu-16-04-lts

报错三

linux/netfilter/xt_dscp.h: No such file or directory:

这个问题比较特殊。 AOSP源码在 external\iptables\include\linux\netfilter 目录下存在“重名文件”,比如:

  1. xt_DSCP.h
  2. xt_dscp.h
  3. xt_MARK.h
  4. xt_mark.h

这些文件名字母相同,但是大小写不同。由于Linux文件系统对文件名字母大小写敏感,所以这些被认为是不同文件。然而Windows系统对文件名字母大小写不敏感,所以Windows下不能创建字母相同但大小写不同的多个文件。我曾经在Windows系统下直接复制粘贴了AOSP源码目录,所以导致这些同名文件中的一个被覆盖。

解决方法:

  1. 只在Linux系统下进行操作可避免此问题。
  2. 如果文件已经丢失,可以直接去Google在线仓库下载:https://android.googlesource.com/platform/external/iptables/+/lollipop-release/include/linux/netfilter/

报错四

****************************
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.
****************************

这个错误源于aapt的一个解析bug,具体分析可参考:https://plus.google.com/+hashcode0f/posts/URHo3hBmfHY

解决方法:
找到文件 system\core\libutils\String8.cpp,将第427行的 memcpy 改为 memmove

             next = len;
         }
 
-        memcpy(buf + tail, buf + index + skip, next - index - skip);
+        memmove(buf + tail, buf + index + skip, next - index - skip);
         tail += next - index - skip;
         index = next;
     }

编译速度慢

这并不是AOSP相关的问题,但是影响编译速度,所以记录一下。
原来使用老的笔记本(CPU为i7 4720HQ,Ubuntu 14.04),编译 Android 5.0 仅需要不到两个小时时间,然而此次用的新电脑(CPU为i7 7700HQ, Ubuntu 18.04), 编译 Android 5.0 连续运行了将近5个小时依旧没有结束。经查看发现CPU主频被自动限制在了最低频率800mHz,相当于电脑一直在一最低性能运行。目前这个频率限制的原因还不清楚。

解决方法:
可以使用 cpufrequtils 手动设置CPU频率:

安装:

sudo apt-get install cpufrequtils

查看CPU信息:

sudo cpufreq-info 

设置CPU为高性能模式:

cpufreq-set -g performance

猜你喜欢

转载自blog.csdn.net/mayazure/article/details/85839964