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

说明:

  • 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版本

apt-get install openjdk-7-jdk python
  1. 额外添加自己常用工具
  • htop
  • tree
  • vim

apt-get install -y htop tree vim

编译报错

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,宏处理器,安装它

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的第三方安全库,故需要进行额外配置:

2.1 下载 bcprov-jdk-xxx.jar包

下载地址: http://www.bouncycastle.org/latest_releases.html

找到对应自己jdk版本的 bcprov-jdk****.jar 包下载,我这是ubuntu14.04下载的默认jdk版本,1.7.0_201

故下载了 JDK 1.5 - JDK 1.11: bcprov-jdk15on-165.jar

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 包放入

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

posted @ 2020-05-24 20:57 汪氵淼阅读( ... )  评论( ... ) 编辑

我来评几句
登录后评论

已发表评论数()

相关站点

热门文章