Compiling android source code in Docker environment | Compiling runnable xposed

Links to the original text: https://www.imisty.cn/?p=207

Preface

Because my computer is the version of Ubuntu 18, after successfully compiling xposed and brushing into the mobile phone, it can't start, checking all the environments, no problem, it may be the compatibility Library of Ubuntu system, but I can't reinstall the system, after all, it's a bit silly, so the best way is in docker's Ubuntu container. Compilation, unification of environmental issues, can also isolate the environment at ordinary times
Work development environment, start below

Install and configure docker

Doker acceleration, using a nationally friendly mirror address

To use the accelerator by modifying the daemon configuration file/etc/docker/daemon.json, execute the following commands:

You can configure the Docker daemon to default Docker official image acceleration. This allows you to accelerate the pull-out of the image by default through the official image without specifying registry.docker-cn.com at each pull-out.

Temporary Effectiveness: You can pass in the -- registry-mirror parameter when the Docker daemon starts: $docker --registry-mirror=https://registry.docker-cn.com daemon

Permanently retain the changes, you can modify the / etc/docker/daemon.json file and add the registry-mirrors key value.

$ sudo mkdir -p /etc/docker
$ sudo tee /etc/docker/daemon.json <<-'EOF'
{
  "registry-mirrors": ["https://registry.docker-cn.com"]
}
EOF
$ sudo systemctl daemon-reload
$ sudo systemctl restart docker

Pull Ubuntu Mirror

Because we compiled Android 6.0 system, we recommend Ubuntu 14.04 x64 system to compile, which can save a lot of trouble (such as compiler version, build suite version, dependency library version and other incompatible issues), which is why we use docker.

Execute the following command to get the image:
sudo docker pull ubuntu:14.04 # docker defaults to 64-bit systems

Query for local mirrors

Query local existing mirrors (note mirror number - IMAGE ID)

$ sudo docker images

misty@ubuntu:/etc/docker$ sudo docker images
REPOSITORY           TAG                 IMAGE ID            CREATED             SIZE
ubuntu               14.04               2c5e00d77a67        6 weeks ago         188MB
rethinkdb            latest              cc5badcd88e8        7 weeks ago         184MB
nginx                latest              53f3fd8007f7        7 weeks ago         109MB
openstf/stf          latest              f8f8d84596a0        7 weeks ago         784MB
sorccu/adb           latest              7123ee61b746        15 months ago       30.5MB
openstf/ambassador   latest              b1f0eb8297cf        3 years ago         6.46MB

View local containers

misty@ubuntu:/etc/docker$ sudo docker ps -a

Start Mirror

Here we use warehouse: label sudo docker run-it ubuntu: 14.04/bin/bash so that we can get a pseudo-terminal

# Start the mirror and get a pseudo-terminal
# Note: The actual boot is the container. When booting the image, a new container will be created automatically and started.
$ sudo docker run -it <REPOSITORY:TAG> /bin/bash   # Start with Warehouse Name + Label
$ sudo docker run -it <IMAGE ID> /bin/bash     # Start with IMAGE ID
# Exit mirror
>> $ exit   # Or use the shortcut key Ctrl + D

Replacement of System Source

It seems that there is a problem with vi here, so it is recommended to write in a redirected way, referring to the modification of the configuration docker image address.

>> # cp /etc/apt/sources.list /etc/apt/sources.list.bak
>> # echo "New Data Source">/etc/apt/sources.list//Replace with New Data Source
>> # apt-get update
>> # exit
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

Add Chinese Language Support

Add Chinese Language Support
Start the specified container and enter the Ubuntu container to perform the operation:

>> $ locale       #Query the current language
>> $ locale -a    #Query Support Language
# If UTF-8 is not supported, add UTF-8 language support
>> $ apt-get install language-pack-zh-hant language-pack-zh-hans # Chinese
>> $ language-pack-en # English
# Modify the / etc/profile file and add:
export LANG=zh_CN.UTF-8
export LANGUAGE=zh_CN:zh
# Reload resources
>> $ source /etc/profile

Correction of time zone time

Start the specified container and enter the Ubuntu container to perform the operation:

>> $ date  # View the current time
>> $ cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
>> $ echo 'Asia/Shanghai' >/etc/timezone

Configure compiler-specific images

Use the following commands to create a container and mount the ~/share directory to the / home/share directory in the container:
$ docker run -it -v ~/share:/home/share ubuntu:14.04 /bin/bash

Description: A directory is mounted here in the container to facilitate later operation.

Adding 64-bit system support for 32-bit
1 > Check if support is available

>> $ dpkg --print-architecture     # If supported, output amd64
>> $ dpkg --print-foreign-architectures    # If supported, output i386

Manual Open Support

>> $ sudo dpkg --add-architecture i386
>> $ sudo apt-get update

Update all software (unnecessary)
>> $ sudo apt-get dist-upgrade

Install only support libraries (previously required to install ia32-libs, currently replaced by three libraries)

$ sudo apt-get install lib32z1 lib32ncurses5 lib32bz2-1.0

Adding dependencies needed to compile Android source code
Install compiler tools and build suites:

$ sudo apt-get install gcc-multilib g++-multilib build-essential

Install the necessary tools and software

>> $ sudo apt-get install git-core gnupg bison flex gperf pngcrush bc zip curl lzop 
>> $ sudo apt-get install schedtool libxml2 libxml2-utils xsltproc squashfs-tools 

Install other required libraries

>> $ sudo apt-get install libesd0-dev libsdl1.2-dev libwxgtk2.8-dev libswitch-perl 
>> $ sudo apt-get install libssl1.0.0 libssl-dev lib32readline-gplv2-dev libncurses5-dev

Attachment: Instructions:

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
 The xsltproc fast XSLT engine can convert XML into HTML,XHTML,PDF through XSL files.
Scheme tool queries or sets CPU status
 Squashfs-tools Linux Kernel Compression Tool, Read-Only Compressed File System Image
 PNG Crush Batch Compression PNG Pictures
 Libxml 2 libxml 2-utils Operating XML Document Tool

The submission container is saved as a mirror

After configuring the environment, save the container as a mirror:

$ sudo docker commit -m "xxx" <CONTAINER ID> <TEPO:TAG>

For example, using the $docker PS-A instruction to query the container number just now is a61adfb1953, and we save it as a local image, which can be executed:

$ sudo docker commit -m "local_ubuntu14" 7e242d3a00ae local_ubuntu14:ubuntu_v1.0

Using $docker images, you can view the newly generated image:

misty@ubuntu:~/share$ sudo docker images
REPOSITORY           TAG                 IMAGE ID            CREATED             SIZE
local_ubuntu14       ubuntu_v1.0         97793b37c017        15 seconds ago      796MB
ubuntu               14.04               2c5e00d77a67        6 weeks ago         188MB
rethinkdb            latest              cc5badcd88e8        7 weeks ago         184MB
nginx                latest              53f3fd8007f7        7 weeks ago         109MB
openstf/stf          latest              f8f8d84596a0        7 weeks ago         784MB
sorccu/adb           latest              7123ee61b746        15 months ago       30.5MB
openstf/ambassador   latest              b1f0eb8297cf        3 years ago         6.46MB

Start the container based on the submitted local mirror and mount the source directory of the host host's Android to the mirror's aosp directory
sudo docker run -it -v ~/bin:/home/aosp local_ubuntu14 /bin/bash

Pre-compile environment preparation-environment list

Host system: ubuntu18.0.4LTS
Host: java version "1.8.0_211"
docker Server Version: 18.09.5
Kernel Version: 4.18.0-25-generic
Mirror: Ubuntu 14.04
Container source version: android-6.0.1_r11
In-container Java version: java version "1.7.0_201"

Pre-compilation Notes

  • Docker-related files are in the / var/lib/docker directory

Start compiling Android source code and xposed

  1. Enter sudo docker exec-it [container id]/bin/bash inside the container

2... Configure perl environment reference Android source code compiler article configuration

  1. Here I am compiling XposedBridge in Ubuntu, compiling xposed in container (pay attention to modifying configuration file and output directory). The advantage is that environment can be separated. Java 8 is configurated in Ubuntu and Java 7 is configurated in container. In fact, I am too lazy to install and configure environment again. Anyway, all mappings are from the same source. Code catalogue
    • Under the host XposedTools project. / buile.pl -a java started compiling XposedBridge
  2. Start compiling Xposed
    • Before compiling, you need to check that XposedBridge is placed in the Java folder of the output directory. The xposed project replaces the original art in the source directory under $aosp/frameworker/bash/cmds/xposed, and the xposed_art is switched to the corresponding source version branch under $aosp/art.
    • Under the host XposedTools project. / buile.pl-t arm64:23, Xposed is compiled.

Common problem solving

USER problem (because the running docker does not configure USER environment variables)

including ./tools/external/fat32lib/Android.mk ...
Install: out/host/linux-x86/framework/jack.jar
out/host/linux-x86/bin/jack-admin: line 27: USER: unbound variable
make: *** [out/host/linux-x86/framework/jack.jar] Error 1
make: *** Deleting file `out/host/linux-x86/framework/jack.jar'

#### make failed to build some targets (41 seconds) ####

Solution:

  • export USER=$(whoami)
  • Or ENV USER root // can be the name you need.

Error log details

Last 10 lines from the log:
   target Unpacked: patchoat (out/target/product/generic_arm64/obj_arm/EXECUTABLES/patchoat_intermediates/PACKED/patchoat)
   target Symbolic: patchoat (out/target/product/generic_arm64/symbols/system/bin/patchoat)
   target Strip: patchoat (out/target/product/generic_arm64/obj_arm/EXECUTABLES/patchoat_intermediates/patchoat)
   Install: out/target/product/generic_arm64/system/bin/patchoat
   collect2: error: ld returned 1 exit status
   make: *** [out/target/product/generic_arm64/obj_arm/SHARED_LIBRARIES/libxposed_art_intermediates/LINKED/libxposed_art.so] Error 1
   make: *** Waiting for unfinished jobs....
   
   #### make failed to build some targets (04:32 (mm:ss)) ####

Because the source code compiled on Ubuntu 18 has been taken directly before, this problem has arisen. The implementation of git status in the source directory has found that the can editor has been changed. Calculate, restore the environment directly, retrieve the corresponding part of art6.0 of xposed_art on guthub, and recompile it, as a matter of fact, there is no problem, and it has been successfully compiled and passed.

Solution of Card Boot Interface

After successful compilation, brush in the phone card on the boot interface and get the log

Failed to dlopen libart.so: dlopen failed: cannot locate symbol "__android_log_error_write" referenced by "/system/lib64/libart.so"...

Add: LOCAL_LDFLAGS+=-fuse-ld=bfd to the compiler script Android.mk of libxxx.so in your error-reporting Library

# Direct Addition
ifeq (1,$(strip $(shell expr $(PLATFORM_SDK_VERSION) \>= 22)))
  LOCAL_WHOLE_STATIC_LIBRARIES := libsigchain
  LOCAL_LDFLAGS := -Wl,--version-script,art/sigchainlib/version-script.txt -Wl,--export-dynamic
  LOCAL_LDFLAGS += -fuse-ld=bfd
endif

After this change, it may be reported that unrecognized option'- icf=safe'

As expected, the following errors occurred in the compilation after the modification.

Last 10 lines from the log:
   target Symbolic: xposed (out/target/product/generic_arm64/symbols/system/bin/app_process64_xposed)
   target Strip (keep symbols): xposed (out/target/product/generic_arm64/obj/EXECUTABLES/xposed_intermediates/app_process64_xposed)
   /home/aosp/WORKING_DIRECTORY/prebuilts/gcc/linux-x86/arm/arm-linux-androideabi-4.9/bin/../lib/gcc/arm-linux-androideabi/4.9.x-google/../../../../arm-linux-androideabi/bin/ld.bfd: unrecognized option '--icf=safe'
   /home/aosp/WORKING_DIRECTORY/prebuilts/gcc/linux-x86/arm/arm-linux-androideabi-4.9/bin/../lib/gcc/arm-linux-androideabi/4.9.x-google/../../../../arm-linux-androideabi/bin/ld.bfd: use the --help option for usage information
   collect2: error: ld returned 1 exit status
   make: *** [out/target/product/generic_arm64/obj_arm/EXECUTABLES/xposed_intermediates/LINKED/app_process32_xposed] Error 1
   make: *** Waiting for unfinished jobs....

   #### make failed to build some targets (43 seconds) ####

Solution:
Modify the assignment of line P134 in TARGET_linux-arm.mk to TARGET_GLOBAL_LDFLAGS, and remove - icf=safe

The path is found by using the following command, and find. / - Iname TARGET_linux-arm. MK is executed in the source directory.
The path is $aosp/build/core/combo/TARGET_linux-arm.mk

These two methods are just trying, but they can't solve the problem in fact. The second one directly leads to the compilation can't pass. After reconfiguring the unified environment, we can successfully solve the problem and brush into the mobile phone to run perfectly.

Submitting a successfully compiled container to a mirror causes the root partition to burst

sudo docker commit "commit images" [containerId] myaosp:v1.0 ;

Half of the execution, the root directory will be full, ha ha, stop ctrl +c quickly, maybe with me to mount the AOSP directory of the host and pull out the new AOSP in the container, the amount of data is too large.
Solution:
Temporary Solution: Find a lot of ways to clean up Linux on the internet. It's not easy to operate. After all, it's better to be cautious when it comes to cleaning up files. If you don't want to go back to the pre-liberation stage, restart docker and release part of it first.

Start the system CTL start docker (this command will do)
Daemon restart sudo system CTL daemon-reload
 Restart docker service system CTL restart docker
 Restart docker service sudo service docker restart
 Close docker service docker stop
 Close docker system CTL stop docker

Write at the end

Thank you for the reference provided by this blogger. Compiling Android System Source Code with Docker

Tags: Docker Ubuntu sudo Linux

Posted on Tue, 06 Aug 2019 01:23:51 -0700 by Robert Plank