android source code linux environment configuration and compilation method

Install dependent libs

sudo apt-get install openjdk-11-jdk;#安装jdk

sudo apt-get install libx11-dev:i386 libreadline6-dev:i386 libgl1-mesa-dev
sudo apt-get install -y git flex bison gperf build-essential libncurses5-dev:i386
sudo apt-get install tofrodos python-markdown libxml2-utils xsltproc zlib1g-dev:i386
sudo apt-get install dpkg-dev libsdl1.2-dev
sudo apt-get install git-core gnupg flex bison gperf build-essential
sudo apt-get install zip curl zlib1g-dev gcc-multilib
sudo apt-get install libc6-dev-i386
sudo apt-get install lib32ncurses5-dev x11proto-core-dev libx11-dev
sudo apt-get install libgl1-mesa-dev libxml2-utils xsltproc unzip m4
sudo apt-get install lib32z-dev ccache;
sudo apt-get install libssl-dev libncurses5;

Download repo tool

sudo apt install curl

mkdir ~/bin
PATH=~/bin:$PATH
curl https://storage.googleapis.com/git-repo-downloads/repo > ~/bin/repo
chmod a+x ~/bin/repo

Change source

1. Modify the permissions of the restored source file

sudo chmod 777 /etc/apt/sources.list

2. Backup files

sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak

3. Modify
Tsinghuayuan
address:https://mirrors.tuna.tsinghua.edu.cn/help/ubuntu/

# 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-updates main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-updates main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-backports main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-backports main restricted universe multiverse

# deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-security main restricted universe multiverse
# # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-security main restricted universe multiverse

deb http://security.ubuntu.com/ubuntu/ jammy-security main restricted universe multiverse
# deb-src http://security.ubuntu.com/ubuntu/ jammy-security main restricted universe multiverse

# 预发布软件源,不建议启用
# deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-proposed main restricted universe multiverse
# # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-proposed main restricted universe multiverse

Source: University of Science and Technology of China
Address:https://lug.ustc.edu.cn/wiki/mirrors/help/ubuntu/

# 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释
deb https://mirrors.ustc.edu.cn/ubuntu/ xenial main restricted universe multiverse
# deb-src https://mirrors.ustc.edu.cn/ubuntu/ xenial main main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ xenial-updates main restricted universe multiverse
# deb-src https://mirrors.ustc.edu.cn/ubuntu/ xenial-updates main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ xenial-backports main restricted universe multiverse
# deb-src https://mirrors.ustc.edu.cn/ubuntu/ xenial-backports main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ xenial-security main restricted universe multiverse
# deb-src https://mirrors.ustc.edu.cn/ubuntu/ xenial-security main restricted universe multiverse
 
# 预发布软件源,不建议启用
# deb https://mirrors.ustc.edu.cn/ubuntu/ xenial-proposed main restricted universe multiverse
# deb-src https://mirrors.ustc.edu.cn/ubuntu/ xenial-proposed main restricted universe multiverse

Aliyuan
address:https://developer.aliyun.com/mirror/ubuntu

deb http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse

4.Update

sudo apt-get update
sudo apt-get upgrade

Initialization and synchronization

method one:

curl -OC - https://mirrors.tuna.tsinghua.edu.cn/aosp-monthly/aosp-latest.tar # 下载初始化包
tar xf aosp-latest.tar
cd AOSP   # 解压得到的 AOSP 工程目录
# 这时 ls 的话什么也看不到,因为只有一个隐藏的 .repo 目录
repo sync # 正常同步一遍即可得到完整目录
# 或 repo sync -l 仅checkout代码

Method Two:

mkdir WORKING_DIRECTORY
cd WORKING_DIRECTORY
repo init -u https://mirrors.tuna.tsinghua.edu.cn/git/AOSP/mirror/manifest#默认最新

#选择特定版本
repo init -u https://mirrors.tuna.tsinghua.edu.cn/git/AOSP/platform/manifest -b android-10.0.0_r1
repo init -u https://mirrors.tuna.tsinghua.edu.cn/git/AOSP/platform/manifest -b android-13.0.0_r6

repo sync	#同步(全仓下载)

#单仓下载方式
repo sync -c platform/frameworks/base
repo sync -c platform/frameworks/native
repo sync -c system/core

Note:
If it prompts that it cannot connect togerrit.googlesource.com
Insert image description here

curl https://mirrors.tuna.tsinghua.edu.cn/git/git-repo -o repo
chmod +x repo
export REPO_URL='https://mirrors.tuna.tsinghua.edu.cn/git/git-repo'

If you are prompted that your identity is unknown, just follow the prompts to set your email and name.
Insert image description here

compile

. build/envsetup.sh
lunch sdk_phone_x86_64 #must this
make -j16#全仓编译

After the compilation is completed, enter the command emulatorto run the simulator
. Note: The first compilation must be compiled in full.

After compiling for the first time, if you don’t want to compile again and run the simulator directly, you can use the following command

. build/envsetup.sh
lunch sdk_phone_x86_64 #must this
emulator

Common single module compilation
module: make SystemUI
Code path: frameworks\base\packages\SystemUI
Generated package directory: out/target/product/emulator_x86_64/system_ext/priv-app/SystemUI
adb push SystemUI.apk /system_ext/priv-app/SystemUI

Module: make services
Code path: frameworks\base\services
Generated package directory: out/target/product/emulator_x86_64/system/framework/services.jar
adb push services.jar /system/framework/

Module: make framework
Code path: frameworks\base\
Generated package directory: out/target/product/emulator_x86_64/system/framework/framework.jar
adb push framework.jar /system/framework/

Module: make framework-res
Code path: frameworks\base\core\res
Generated package directory: out/target/product/emulator_x86_64/system/framework/framework-res.apk
adb push framework-res.jar /system/framework/
Note : It is recommended make frameworkto first Compile this module because framework-res depends on framework

Module: make inputflinger
Code path: frameworks/native/services/inputflinger
Generated package directory:
out/target/product/emulator_x86_64/system/lib/libinputflinger.so
out/target/product/emulator_x86_64/system/lib64/libinputflinger.so
adb push libinputflinger. so system/lib
adb push libinputflinger.so system/lib64

Note: After compiling a single warehouse, remember to push it to the corresponding file directory and restart to take effect.

other

init 
make init 
mmm system/core/init

zygote 
make app_process 
mmm frameworks/base/cmds/app_process

system_server 
make services 
mmm frameworks/base/services

java framework 
make framework 
mmm frameworks/base

framework资源
make framework-res 
mmm frameworks/base/core/res

jni framework 
make libandroid_runtime
mmm frameworks/base/core/jni
 
binder
make libbinder
mmm frameworks/native/libs/binder

Compilation error
Tip: ninja failed with: exit status 137
If the value of the javacheap file gedit build/soong/java/config/config.go
Insert image description here
is too small, it will be killed directly by the system.
export MAVEN_OPTS="-Xms8192m -Xmx8192m"
Generally, half of the memory value of your own computer is configured.

After modification, remember to clear the out directory before compiling, and it must be cleared:rm -rf out

To check whether the configuration has taken effect after compilation, you can check this file: , search JavacHeapSizeout/soong/build.ninja in this file to see if this value is the value you set.

Import source code into android studio

  1. Enter the source code root directory and initialize the system environment
    source build/envsetup.sh
  2. Execute the following command in the source code root directory to generate idegen.jar
    mmm development/tools/idegen/
  3. Execute in the source code root directory
    sudo development/tools/idegen/idegen.sh
  4. Modify permissions
    sudo chmod 777 android.iml
    sudo chmod 777 android.ipr
  5. Filter module
    Use a text editor to open the android.iml file, search for the keyword "excludeFolder", and add the modules that do not need to be loaded here.
    I have retained the frameseworks, render, packages, and system modules here, and filtered out the others. The reference is as follows:
<excludeFolder url="file://$MODULE_DIR$/./external/emma"/>
<excludeFolder url="file://$MODULE_DIR$/./external/jdiff"/>
<excludeFolder url="file://$MODULE_DIR$/out/eclipse"/>
<excludeFolder url="file://$MODULE_DIR$/.repo"/>
<excludeFolder url="file://$MODULE_DIR$/external/bluetooth"/>
<excludeFolder url="file://$MODULE_DIR$/external/chromium"/>
<excludeFolder url="file://$MODULE_DIR$/external/icu4c"/>
<excludeFolder url="file://$MODULE_DIR$/external/webkit"/>
<excludeFolder url="file://$MODULE_DIR$/frameworks/base/docs"/>
<excludeFolder url="file://$MODULE_DIR$/out/host"/>
<excludeFolder url="file://$MODULE_DIR$/out/target/common/docs"/>
<excludeFolder url="file://$MODULE_DIR$/out/target/common/obj/JAVA_LIBRARIES/android_stubs_current_intermediates"/>
<excludeFolder url="file://$MODULE_DIR$/out/target/product"/>
<excludeFolder url="file://$MODULE_DIR$/prebuilt"/>
<excludeFolder url="file://$MODULE_DIR$/art" />
<excludeFolder url="file://$MODULE_DIR$/bionic" />
<excludeFolder url="file://$MODULE_DIR$/bootable" />
<excludeFolder url="file://$MODULE_DIR$/build" />
<excludeFolder url="file://$MODULE_DIR$/compatibility" />
<excludeFolder url="file://$MODULE_DIR$/dalvik" />
<excludeFolder url="file://$MODULE_DIR$/cts" />
<excludeFolder url="file://$MODULE_DIR$/developers" />
<excludeFolder url="file://$MODULE_DIR$/developers/samples" />
<excludeFolder url="file://$MODULE_DIR$/development" />
<excludeFolder url="file://$MODULE_DIR$/devices" />
<excludeFolder url="file://$MODULE_DIR$/docs" />
<excludeFolder url="file://$MODULE_DIR$/external" />
<excludeFolder url="file://$MODULE_DIR$/flashing-files" />
<excludeFolder url="file://$MODULE_DIR$/hardware" />
<excludeFolder url="file://$MODULE_DIR$/kernel" />
<excludeFolder url="file://$MODULE_DIR$/libcore" />
<excludeFolder url="file://$MODULE_DIR$/libnativehelper" />
<excludeFolder url="file://$MODULE_DIR$/out" />
<excludeFolder url="file://$MODULE_DIR$/pdk" />
<excludeFolder url="file://$MODULE_DIR$/platform_testing" />
<excludeFolder url="file://$MODULE_DIR$/prebuilt" />
<excludeFolder url="file://$MODULE_DIR$/prebuilts" />
<excludeFolder url="file://$MODULE_DIR$/shortcut-fe" />
<excludeFolder url="file://$MODULE_DIR$/sdk" />
<excludeFolder url="file://$MODULE_DIR$/test" />
<excludeFolder url="file://$MODULE_DIR$/toolchain" />
<excludeFolder url="file://$MODULE_DIR$/tools" />
  1. Import the source code Android Studio opens the android.ipr
    file under the project source code and starts loading the code.

Swap space swap configuration (optional)

There may be errors such as FAILED: out/soong/build.ninja during the compilation process. You can configure swap and then compile.

1. Create a file to be used as a swap partition: increase the count size of the swap partition. The command is written as follows, where count is equal to the number of blocks you want (bs*count=file size).
dd if=/dev/zero of=/var/swapfile bs=1024 count=16777216
The value of count here is generally consistent with the memory of your own computer. Here it is 1024 x 1024 = 16G.

2. Format as a swap partition file:
mkswap /var/swapfile
Create a swap file system

3. Modify permissions
chmod -R 0600 /var/swapfile

4. Enable swap partition file:
swapon /var/swapfile
enable swap file

If the swap file is enabled and an error is reported, the prompt is: swapon failed: the device or resource is busy.
You can close the swap file first swapoff /var/swapfileand then use swapon to open it.

5. To enable the system automatically when booting, add a line in the file /etc/fstab:
vi /etc/fstab
Enter the file
/var/swapfile swap swap defaults 0 0
Insert image description here
Note: 1. If you have insufficient permissions, remember to add sudo
in front of the command 2. It is a custom swap partition path, which can be named according to your preference.
/var/swapfile

other

1. Screenshot:
Install the screenshot tool sudo apt install flameshot and run flameshot gui the screenshot

2. Solve problems in apt-get installationE: Sub-process /usr/bin/dpkg returned an error code (1)

cd /var/lib/dpkg/
sudo mv info/ info_bak          # 现将info文件夹更名
sudo mkdir info                 # 再新建一个新的info文件夹
sudo apt-get update             # 更新
sudo apt-get -f install         # 修复
sudo mv info/* info_bak/        # 执行完上一步操作后会在新的info文件夹下生成一些文件,现将这些文件全部移到info_bak文件夹下
sudo rm -rf info                # 把自己新建的info文件夹删掉
sudo mv info_bak info           # 把以前的info文件夹重新改回名

reference

https://mirrors.tuna.tsinghua.edu.cn/help/AOSP/
https://lug.ustc.edu.cn/wiki/mirrors/help/aosp/

Guess you like

Origin blog.csdn.net/yimelancholy/article/details/130462470