Docker compiles Android 6.0 source code

docker environment configuration

  1. Correct time zone time
# View current time
$ date
# Modify current time
$ cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
echo 'Asia/Shanghai' > /etc/timezone
  1. Replace the software source to 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. Add schema support
dpkg --add-architecture i386
dpkg --add-architecture amd64
  1. Add dependency
apt-get install lib32z1 lib32ncurses5 lib32bz2-1.0
  1. Add Android source dependency
# Compile tools, build Suites
apt-get install gcc-multilib g++-multilib build-essential
# Necessary software
apt-get install git-core gnupg bison flex gperf pngcrush bc zip curl lzop
apt-get install schedtool libxml2 libxml2-utils xsltproc squashfs-tools
# library
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

explain:

  • bc command line calculator
  • lzop fast compression tool
  • flex lexical analyzer generator
  • curl URL based file transfer tool
  • gperf hash function generator
  • bison parser generator
  • xsltproc fast XSL T engine can transform XML into HTML,XHTML,PDF
  • schedtool query or set CPU status
  • Squashfs tools Linux kernel compression tool, read-only compression file system Image
  • pngcrush bulk compress PNG pictures
  • Libxml2 libxml2 utils operation XML document tool
  1. Add jdk1.7 and python

Default jdk and python versions installed

apt-get install openjdk-7-jdk python
  1. Add your own common tools
  • htop
  • tree
  • vim

apt-get install -y htop tree vim

Compile error

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

Missing m4 tool, m4 - macro processor, macro processor, install it

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

Because the third-party security library of jdk is added, additional configuration is required:

2.1 download bcprov JDK- xxx.jar package

Download address: http://www.bouncycastle.org/latest_releases.html

Find the bcprov jdk * * *. Jar package corresponding to your own jdk version to download. This is the default jdk version downloaded by Ubuntu 14.04, 1.7.0_ Two hundred and one

So download JDK 1.5 - JDK 1.11: bcprov-jdk15on-165.jar

2.2 put it into Java_ Under home / JRE / lib / ext

JAVA_HOME can echo $JAVA_HOME get or see java.conf Or find the directory corresponding to the current Java by means of which java

This is / usr/lib/jvm/java-7-openjdk-amd64/jre/lib/ext, put the jar package above into

2.3 modification java.security file

Modify JAVA_HOME/jre/lib/security/java.security File, add below

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

Note: if you put in a jar package that does not correspond to your jdk version, you may also report java.lang.VerifyError error

3. USER: unbound variable

Old problem, because docker does not set USER environment variable

I will import export USER=$(whoami) to / etc/bash.bashrc For reuse in the docker environment

You can also set your own name ENV USER root

Tags: Java Ubuntu JDK Linux

Posted on Sun, 24 May 2020 19:17:31 -0700 by danlayton00