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
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章