Docker編譯Android6.0源碼

docker環境配置

  1. 更正時區時間
# 查看當前時間
$ date
# 修改當前時間
$ cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
echo 'Asia/Shanghai' > /etc/timezone
  1. 更換軟件源至aliyun
cp /etc/apt/sources.list /etc/apt/sources.list.bak
echo "
# Ubuntu14.0 aliyun source:
deb http://mirrors.aliyun.com/ubuntu/ trusty main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ trusty-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ trusty-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ trusty-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ trusty-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ trusty main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ trusty-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ trusty-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ trusty-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ trusty-backports main restricted universe multiverse
" > /etc/apt/sources.list
apt update
  1. 添加架構支持
dpkg --add-architecture i386
dpkg --add-architecture amd64
  1. 添加依賴
apt-get install lib32z1 lib32ncurses5 lib32bz2-1.0
  1. 添加安卓源碼依賴
# 編譯工具、構建套件
apt-get install gcc-multilib g++-multilib build-essential
# 必要軟件
apt-get install git-core gnupg bison flex gperf pngcrush bc zip curl lzop
apt-get install schedtool libxml2 libxml2-utils xsltproc squashfs-tools
# 庫
apt-get install libesd0-dev libsdl1.2-dev libwxgtk2.8-dev libswitch-perl
apt-get install libssl1.0.0 libssl-dev lib32readline-gplv2-dev libncurses5-dev

說明:html

  • bc 命令行計算器
  • lzop 快速壓縮工具
  • flex 詞法分析器生成器
  • curl 基於URL的文件傳輸工具
  • gperf 哈希函數生成器
  • bison 語法分析器生成器
  • xsltproc 快速XSLT引擎,能夠經過XSL文件把XML轉爲HTML,XHTML,PDF...
  • schedtool 查詢或設置CPU狀態
  • squashfs-tools linux內核壓縮工具,只讀式壓縮文件系統Image
  • pngcrush 批量壓縮PNG圖片
  • libxml2 libxml2-utils 操做XML文檔工具
  1. 添加jdk1.7和python

安裝的默認的jdk和python版本java

apt-get install openjdk-7-jdk python
  1. 額外添加本身經常使用工具
  • htop
  • tree
  • vim

apt-get install -y htop tree vimpython

編譯報錯

1. fatal internal error, exec of /usr/bin/m4 failed

flex-2.5.39: fatal internal error, exec of /usr/bin/m4 failed
frameworks/base/tools/aidl/aidl_language_l.l:55: warning, rule cannot be matched
prebuilts/misc/linux-x86/bison/bison: m4 subprocess failed
make: *** [out/host/linux-x86/obj/EXECUTABLES/aidl_intermediates/aidl_language_l.cpp] Error 1
make: *** Deleting file `out/host/linux-x86/obj/EXECUTABLES/aidl_intermediates/aidl_language_l.cpp'
make: *** Waiting for unfinished jobs....
make: *** [out/host/linux-x86/obj/EXECUTABLES/aidl_intermediates/aidl_language_y.cpp] Error 1

缺乏m4工具,m4 - macro processor,宏處理器,安裝它linux

apt-get install m4

2. java.lang.NoClassDefFoundError

Exception in thread "main" java.lang.NoClassDefFoundError: org/bouncycastle/jce/provider/BouncyCastleProvider
	at java.lang.Class.getDeclaredMethods0(Native Method)
	at java.lang.Class.privateGetDeclaredMethods(Class.java:2625)
	at java.lang.Class.getMethod0(Class.java:2866)
	at java.lang.Class.getMethod(Class.java:1676)
	at sun.launcher.LauncherHelper.getMainMethod(LauncherHelper.java:494)
	at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:486)
Caused by: java.lang.ClassNotFoundException: org.bouncycastle.jce.provider.BouncyCastleProvider
	at java.net.URLClassLoader$1.run(URLClassLoader.java:360)
	at java.net.URLClassLoader$1.run(URLClassLoader.java:349)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.net.URLClassLoader.findClass(URLClassLoader.java:348)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:430)
	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:323)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:363)
	... 6 more

由於加入了jdk的第三方安全庫,故須要進行額外配置:git

2.1 下載 bcprov-jdk-xxx.jar包

下載地址:http://www.bouncycastle.org/latest_releases.htmldocker

找到對應本身jdk版本的 bcprov-jdk****.jar 包下載,我這是ubuntu14.04下載的默認jdk版本,1.7.0_201ubuntu

故下載了 JDK 1.5 - JDK 1.11: bcprov-jdk15on-165.jarvim

2.2 將其放入 JAVA_HOME/jre/lib/ext 下

JAVA_HOME 能夠echo $JAVA_HOME得到或看 java.conf 或 本身 which java 等手段查找當前 java 對應的目錄安全

我這是 /usr/lib/jvm/java-7-openjdk-amd64/jre/lib/ext,將上面的 jar 包放入bash

2.3 修改 java.security 文件

修改 JAVA_HOME/jre/lib/security/java.security 文件,在下面加上

security.provider.x=org.bouncycastle.jce.provider.BouncyCastleProvider

注意:若是放入了和本身jdk版本不對應的jar包,後面編譯可能還會報java.lang.VerifyError錯誤

3. USER: unbound variable

老問題, 因爲docker沒有設置USER環境變量致使

我這將 export USER=$(whoami) 導入 /etc/bash.bashrc 中,以供docker環境重複使用

也能夠設置本身須要的名字 ENV USER root

相關文章
相關標籤/搜索