一、环境搭建前期准备
二、下载 android 9 的源码 本文是采用国内清华源的方式 过程如下:
#安装git,配置自己的git账号
sudo apt-get install git curl
git config --global user.email "xxxx@xx.com"
git config --global user.name "xxxx"
#配置PATH环境变量
mkdir ~/bin
echo "PATH=~/bin:\$PATH" >> ~/.bashrc
source ~/.bashrc
PATH=~/bin:$PATH
curl https:
chmod a+x ~/bin/repo
#创建并初始化aosp仓库目录
mkdir aosp
cd aosp
repo init -u https:
#同步代码
repo sync
过程中报错误1:
robot@ubuntu:~/aosp$ repo init -u https:
Downloading Repo source from https:
fatal: unable to access 'https://gerrit-googlesource.lug.ustc.edu.cn/git-repo/': server certificate verification failed. CAfile: none CRLfile: none
repo: error: "git" failed with exit status 128
cwd: /home/robot/aosp/.repo/repo
cmd: ['git', 'fetch', '--quiet', '--progress', 'origin', '+refs/heads/*:refs/remotes/origin/*', '+refs/tags/*:refs/tags/*']
fatal: cloning the git-repo repository failed, will remove '.repo/repo'
解决办法
robot@ubuntu:~/aosp$ git config --global http.sslverify false
robot@ubuntu:~/aosp$ git config --global https.sslverify false
过程中报错误2:
robot@ubuntu:~/aosp81$ repo init -u https:
/usr/bin/env: ‘python’: No such file or directory
解决办法: 安装python2.7,并设置python的版本默认选择
sudo apt install python2.7
sudo update-alternatives --install /usr/bin/python python /usr/bin/python2.7 1
sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.8 2
解决错误后:
robot@ubuntu:~/aosp81$ repo init -u https:
Downloading manifest from https:
remote: Enumerating objects: 6434, done.
remote: Counting objects: 100% (6434/6434), done.
remote: Compressing objects: 100% (2445/2445), done.
remote: Total 91787 (delta 3304), reused 6049 (delta 3074)
Receiving objects: 100% (91787/91787), 21.52 MiB | 47.90 MiB/s, done.
Resolving deltas: 100% (34756/34756), done.
Your identity is: dtltljb <ljb@lqtech.com>
If you want to change this, please re-run 'repo init' with --config-name
Testing colorized output (for 'repo diff', 'repo status'):
black red green yellow blue magenta cyan white
Enable color display in this user account (y/N)? y
repo has been initialized in /home/robot/aosp81
error: Unable to fully sync the tree.
error: Downloading network changes failed.
Try re-running with "-j1 --fail-fast" to exit at the first error.
robot@ubuntu:~/aosp81$ repo sync -j1 --fail-fast
Fetching: 26% (156/592) platform/prebuilts/gcc/linux-x86/aarch64/aarch64-linux-android-4.9
四、安装依赖包、更新安装源
sudo vim /etc/apt/source.list 把下面内容追加到文件的末尾。
deb https:
deb-src https:
deb https:
deb-src https:
deb https:
deb-src https:
deb https:
deb-src https:
然后执行如下命令 source /etc/apt/source.list sudo apt-get update sudo apt-get upgrade
sudo apt-get install -y libx11-dev:i386 libreadline6-dev:i386 libgl1-mesa-dev g++-multilib
sudo apt-get install -y git flex bison gperf build-essential libncurses5-dev:i386
sudo apt-get install -y tofrodos python-markdown libxml2-utils xsltproc zlib1g-dev:i386
sudo apt-get install -y git-core gnupg flex bison gperf build-essential
sudo apt-get install -y zip curl zlib1g-dev gcc-multilib g++-multilib
sudo apt-get install -y libc6-dev-i386
sudo apt-get install -y lib32ncurses5-dev x11proto-core-dev libx11-dev
sudo apt-get install -y libgl1-mesa-dev libxml2-utils xsltproc unzip m4
sudo apt-get install -y lib32z-dev ccache
sudo apt-get install -y libssl-dev
sudo apt-get install -y libncurses5
## 一次性安装所有库
sudo apt-get install -y libx11-dev:i386 libreadline6-dev:i386 libgl1-mesa-dev g++-multilib flex bison gperf build-essential libncurses5-dev:i386 tofrodos python-markdown libxml2-utils xsltproc zlib1g-dev:i386 git-core gnupg flex bison gperf build-essential zip curl zlib1g-dev gcc-multilib g++-multilib libc6-dev-i386 lib32ncurses5-dev x11proto-core-dev libx11-dev libgl1-mesa-dev libxml2-utils xsltproc unzip m4 lib32z-dev ccache libncurses5
sudo apt install openjdk-8-jdk
五、编译 aosp-8 源码
source build/envsetup.sh
luanch
选择6 编译 aosp_x86_64-eng 即 x86-64 环境的android镜像。 通过lunch指令设置编译目标,就是生成的镜像要运行在什么样的设备上,模拟器是x86的平台,运行速度会更快。这里也可以用编译目标名称如lunch aosp_x86_64-eng,因为不同版本的编译目标名称序号并不相同。
编译目标的格式:BUILD-BUILDTYPE,比如上面的aosp_x86_64-eng的BUILD是aosp_x86_64,BUILDTYPE是eng。BUILD指的是特定功能的组合的特定名称,即表示编译出的镜像可以运行在什么环境。其中,aosp(Android Open Source Project)代表Android开源项目;arm表示系统是运行在arm架构的处理器上,arm64则是指64位arm架构处理器,x86则表示x86架构的处理器。BUILD TYPE则指的是编译类型,通常有三种:
-user:代表这是编译出的系统镜像是可以用来正式发布到市场的版本,其权限是被限制的(如,没有root权限,不能dedug等)
-userdebug:在user版本的基础上开放了root权限和debug权限。
-eng:代表engineer,也就是所谓的开发工程师的版本,拥有最大的权限(root等),此外还附带了许多debug工具。
make -j8
#此参数根据计算机cpu核数有关,通常是根据你机器cup的核心来确定:core*2。
[ 0% 75/89253] Ensuring Jack server is installed and started
FAILED: setup-jack-server
/bin/bash -c "(prebuilts/sdk/tools/jack-admin install-server prebuilts/sdk/tools/jack-launcher.jar prebuilts/sdk/tools/jack-server-4.11.ALPHA.jar 2>&1 || (exit 0) ) && (JACK_SERVER_VM_ARGUMENTS=\"-Dfile.encoding=UTF-8 -XX:+TieredCompilation\" prebuilts/sdk/tools/jack-admin start-server 2>&1 || exit 0 ) && (prebuilts/sdk/tools/jack-admin update server prebuilts/sdk/tools/jack-server-4.11.ALPHA.jar 4.11.ALPHA 2>&1 || exit 0 ) && (prebuilts/sdk/tools/jack-admin update jack prebuilts/sdk/tools/jacks/jack-4.32.CANDIDATE.jar 4.32.CANDIDATE || exit 47 )"
Jack server already installed in "/home/robot/.jack-server"
Launching Jack server java -XX:MaxJavaStackTraceDepth=-1 -Djava.io.tmpdir=/tmp -Dfile.encoding=UTF-8 -XX:+TieredCompilation -cp /home/robot/.jack-server/launcher.jar com.android.jack.launcher.ServerLauncher
Jack server failed to (re)start, try 'jack-diagnose' or see Jack server log
SSL error when connecting to the Jack server. Try 'jack-diagnose'
SSL error when connecting to the Jack server. Try 'jack-diagnose'
ninja: build stopped: subcommand failed.
22:29:09 ninja failed with: exit status 1
#### failed to build some targets (05:31 (mm:ss)) ####
- 解决方法1:
此处修改两处内容,其一 是SSL error when connecting to the Jack server. Try ‘jack-diagnose’,还有一个错误 我可能忘记记录。
修改 jack-server 端口地址,修改方法如下:
(1)
robot@ubuntu:~$ cat .jack-settings
# Server settings
SERVER_HOST=localhost
SERVER_PORT_SERVICE=27755 ## 此处端口号
SERVER_PORT_ADMIN=27765
# Internal, do not touch
SETTING_VERSION=4
(2)
robot@ubuntu:~$ cat .jack-server/config.properties
#
#Fri Oct 15 22:18:39 PDT 2021
jack.server.idle=180
jack.server.max-service.by-mem=1\=2147483648\:2\=3221225472\:3\=4294967296
jack.server.shutdown=21600
jack.server.time-out=7200
jack.server.max-jars-size=104857600
jack.server.service.port=27755 ## 此处端口号
jack.server.admin.port=27765
jack.server.config.version=4
jack.server.max-service=4
jack.server.deep-idle=900
修改第2个内容如下:
文件路径如下: prebuilts/sdk/tools/jack-admin
JACK_SERVER_COMMAND="java -XX:MaxJavaStackTraceDepth=-1 -Djava.io.tmpdir=$TMPDIR $JACK_SERVER_VM_ARGUMENTS -Xmx8000M -cp $LAUNCHER_JAR $LAUNCHER_NAME"
A:prebuilts/sdk/tools/jack-admin 文件,在 JACK_SERVER_COMMAND=“…… -cp ……” -cp 前添加-Xmx8000m(8000m为内存大小的一半左右,根据所用的主机配置而定)
B:通过查看文件 $HOME/.jack-server/logs/jack-server-*.log
JACK_SERVER_VM_ARGUMENTS="${JACK_SERVER_VM_ARGUMENTS:=-Dfile.encoding=UTF-8 -XX:+TieredCompilation -Xmx4096M}"
测试 jack-server 常用命令
jack-admin kill-server/start-server 命令,看start-server是否能够成功运行。
File "build/tools/merge-event-log-tags.py", line 51
except getopt.GetoptError, err:
^
SyntaxError: invalid syntax
[ 0% 54/87502] Lex: applypatch <= bootable/recovery/edify/lexer.ll
FAILED: out/target/product/generic_x86_64/obj/STATIC_LIBRARIES/libedify_intermediates/lexer.cpp
/bin/bash -c "prebuilts/misc/linux-x86/flex/flex-2.5.39 -oout/target/product/generic_x86_64/obj/STATIC_LIBRARIES/libedify_intermediates/lexer.cpp bootable/recovery/edify/lexer.ll"
flex-2.5.39: loadlocale.c:130: _nl_intern_locale_data: Assertion `cnt < (sizeof (_nl_value_type_LC_TIME) / sizeof (_nl_value_type_LC_TIME[0]))' failed.
Aborted (core dumped)
[ 0% 61/87502] build out/target/common/obj/JAVA_LIBRARIES/sdk_v21_intermediates/classes.jack
ninja: build stopped: subcommand failed.
02:14:44 ninja failed with: exit status 1
在~/.bashrc最后添加export LC_ALL=C
编译成功结果记录
warning: no entries written for string/next_action (0x7f0902d7)
warning: no entries written for string/done_action (0x7f0902d8)
warning: no entries written for string/account_folder_list_summary_starred (0x7f0902d9)
warning: no entries written for string/account_folder_list_summary_drafts (0x7f0902da)
warning: no entries written for string/account_folder_list_summary_outbox (0x7f0902db)
warning: no entries written for string/exchange_name (0x7f0902dc)
warning: no entries written for plurals/message_view_attachment_bytes (0x7f110015)
warning: no entries written for plurals/message_view_attachment_kilobytes (0x7f110016)
warning: no entries written for plurals/message_view_attachment_megabytes (0x7f110017)
warning: no entries written for plurals/message_view_attachment_gigabytes (0x7f110018)
[ 90% 79449/87443] target Strip (mini debug info): mdnsd (out/target/product/generic_x86_64/obj/EXECUTABLES/mdnsd_intermediates/mdnsd)
prebuilts/gcc/linux-x86/x86/x86_64-linux-android-4.9/bin/x86_64-linux-android-nm: out/target/product/generic_x86_64/symbols/system/bin/mdnsd: no symbols
[ 90% 79491/87443] target Strip (mini debug info): micro_bench_static (out/target/product/generic_x86_64/obj/EXECUTABLES/micro_bench_static_intermediates/micro_bench_static64)
prebuilts/gcc/linux-x86/x86/x86_64-linux-android-4.9/bin/x86_64-linux-android-nm: out/target/product/generic_x86_64/symbols/system/xbin/micro_bench_static64: no symbols
[ 91% 79593/87443] target Strip (mini debug info): mke2fs_static (out/target/product/generic_x86_64/obj/EXECUTABLES/mke2fs_static_intermediates/mke2fs_static)
prebuilts/gcc/linux-x86/x86/x86_64-linux-android-4.9/bin/x86_64-linux-android-nm: out/target/product/generic_x86_64/symbols/recovery/root/sbin/mke2fs_static: no symbols
[ 91% 79594/87443] target Strip (mini debug info): e2fsdroid_static (out/target/product/generic_x86_64/obj/EXECUTABLES/e2fsdroid_static_intermediates/e2fsdroid_static)
prebuilts/gcc/linux-x86/x86/x86_64-linux-android-4.9/bin/x86_64-linux-android-nm: out/target/product/generic_x86_64/symbols/recovery/root/sbin/e2fsdroid_static: no symbols
[ 91% 79719/87443] target Strip (mini debug info): charger (out/target/product/generic_x86_64/obj/EXECUTABLES/charger_intermediates/charger)
prebuilts/gcc/linux-x86/x86/x86_64-linux-android-4.9/bin/x86_64-linux-android-nm: out/target/product/generic_x86_64/symbols/sbin/charger: no symbols
[ 91% 79886/87443] target Strip (mini debug info): init (out/target/product/generic_x86_64/obj/EXECUTABLES/init_intermediates/init)
prebuilts/gcc/linux-x86/x86/x86_64-linux-android-4.9/bin/x86_64-linux-android-nm: out/target/product/generic_x86_64/symbols/init: no symbols
[ 91% 79910/87443] target Strip (mini debug info): recovery (out/target/product/generic_x86_64/obj/EXECUTABLES/recovery_intermediates/recovery)
prebuilts/gcc/linux-x86/x86/x86_64-linux-android-4.9/bin/x86_64-linux-android-nm: out/target/product/generic_x86_64/symbols/recovery/root/sbin/recovery: no symbols
[ 91% 80087/87443] target Strip (mini debug info): micro_bench_static_32 (out/target/product/generic_x86_64/obj_x86/EXECUTABLES/micro_bench_static_intermediates/micro_bench_static)
prebuilts/gcc/linux-x86/x86/x86_64-linux-android-4.9/bin/x86_64-linux-android-nm: out/target/product/generic_x86_64/symbols/system/xbin/micro_bench_static: no symbols
[ 94% 82281/87443] target Strip (mini debug info): simpleperf (out/target/product/generic_x86_64/obj/EXECUTABLES/simpleperf_intermediates/simpleperf)
prebuilts/gcc/linux-x86/x86/x86_64-linux-android-4.9/bin/x86_64-linux-android-nm: out/target/product/generic_x86_64/symbols/system/xbin/simpleperf: no symbols
[ 94% 82332/87443] target Strip (mini debug info): simpleperf_32 (out/target/product/generic_x86_64/obj_x86/EXECUTABLES/simpleperf_intermediates/simpleperf32)
prebuilts/gcc/linux-x86/x86/x86_64-linux-android-4.9/bin/x86_64-linux-android-nm: out/target/product/generic_x86_64/symbols/system/xbin/simpleperf32: no symbols
[ 94% 82721/87443]
******************************************************
VNDK Abi broken: Please check compatiblity report at : out/soong/.intermediates/hardware/interfaces/neuralnetworks/1.0/android.hardware.neuralnetworks@1.0/android_x86_64_shared_core/android.hardware.neuralnetworks@1.0.so.abidiff
*****************************************************
[ 96% 84379/87443]
******************************************************
VNDK Abi broken: Please check compatiblity report at : out/soong/.intermediates/hardware/interfaces/neuralnetworks/1.0/android.hardware.neuralnetworks@1.0/android_x86_x86_64_shared_core/android.hardware.neuralnetworks@1.0.so.abidiff
*****************************************************
[ 97% 85659/87443]
******************************************************
VNDK Abi broken: Please check compatiblity report at : out/soong/.intermediates/frameworks/av/media/libstagefright/codecs/mpeg2dec/libstagefright_soft_mpeg2dec/android_x86_x86_64_shared_core/libstagefright_soft_mpeg2dec.so.abidiff
*****************************************************
[ 98% 86114/87443] Target userdata fs image: out/target/product/generic_x86_64/userdata.img
Running: mkuserimg.sh out/target/product/generic_x86_64/data out/target/product/generic_x86_64/userdata.img ext4 data 576716800 -D out/target/product/generic_x86_64/system -L data out/target/product/generic_x86_64/obj/ETC/file_contexts.bin_intermediates/file_contexts.bin
make_ext4fs -T -1 -S out/target/product/generic_x86_64/obj/ETC/file_contexts.bin_intermediates/file_contexts.bin -L data -l 576716800 -a data out/target/product/generic_x86_64/userdata.img out/target/product/generic_x86_64/data out/target/product/generic_x86_64/system
Creating filesystem with parameters:
Size: 576716800
Block size: 4096
Blocks per group: 32768
Inodes per group: 7040
Inode size: 256
Journal blocks: 2200
Label: data
Blocks: 140800
Block groups: 5
Reserved block group size: 39
Created filesystem with 89/35200 inodes and 12365/140800 blocks
out/target/product/generic_x86_64/userdata.img maxsize=588791808 blocksize=2112 total=576716800 reserve=5947392
[ 99% 87431/87443] build out/target/product/generic_x86_64/obj/NOTICE.xml
Combining NOTICE files into text
Combining NOTICE files into XML
[ 99% 87434/87443] build out/target/product/generic_x86_64/obj/NOTICE_VENDOR.xml
Combining NOTICE files into text
Combining NOTICE files into XML
[ 99% 87438/87443] Target vendor fs image: out/target/product/generic_x86_64/vendor.img
Running: mkuserimg.sh out/target/product/generic_x86_64/vendor out/target/product/generic_x86_64/vendor.img ext4 vendor 100000000 -D out/target/product/generic_x86_64/system -L vendor out/target/product/generic_x86_64/obj/ETC/file_contexts.bin_intermediates/file_contexts.bin
make_ext4fs -T -1 -S out/target/product/generic_x86_64/obj/ETC/file_contexts.bin_intermediates/file_contexts.bin -L vendor -l 100000000 -a vendor out/target/product/generic_x86_64/vendor.img out/target/product/generic_x86_64/vendor out/target/product/generic_x86_64/system
Creating filesystem with parameters:
Size: 99999744
Block size: 4096
Blocks per group: 32768
Inodes per group: 6112
Inode size: 256
Journal blocks: 1024
Label: vendor
Blocks: 24414
Block groups: 1
Reserved block group size: 7
Created filesystem with 371/6112 inodes and 5567/24414 blocks
out/target/product/generic_x86_64/vendor.img maxsize=102091968 blocksize=2112 total=99999744 reserve=1032768
[ 99% 87439/87443] Create vendor-qemu.img
1+0 records in
2048+0 records out
1048576 bytes (1.0 MB, 1.0 MiB) copied, 0.00485287 s, 216 MB/s
95+1 records in
96+0 records out
100663296 bytes (101 MB, 96 MiB) copied, 0.0745038 s, 1.4 GB/s
1048576+0 records in
1048576+0 records out
1048576 bytes (1.0 MB, 1.0 MiB) copied, 0.714193 s, 1.5 MB/s
Creating new GPT entries.
Warning: The kernel is still using the old partition table.
The new table will be used at the next reboot.
The operation has completed successfully.
Setting name!
partNum is 0
REALLY setting name!
Warning: The kernel is still using the old partition table.
The new table will be used at the next reboot.
The operation has completed successfully.
[ 99% 87441/87443] Target system fs image: out/target/product/generic_x86_64/obj/PACKAGING/systemimage_intermediates/system.img
Running: mkuserimg.sh out/target/product/generic_x86_64/system out/target/product/generic_x86_64/obj/PACKAGING/systemimage_intermediates/system.img ext4 system 2684354560 -D out/target/product/generic_x86_64/system -L system out/target/product/generic_x86_64/obj/ETC/file_contexts.bin_intermediates/file_contexts.bin
make_ext4fs -T -1 -S out/target/product/generic_x86_64/obj/ETC/file_contexts.bin_intermediates/file_contexts.bin -L system -l 2684354560 -a system out/target/product/generic_x86_64/obj/PACKAGING/systemimage_intermediates/system.img out/target/product/generic_x86_64/system out/target/product/generic_x86_64/system
Creating filesystem with parameters:
Size: 2684354560
Block size: 4096
Blocks per group: 32768
Inodes per group: 8192
Inode size: 256
Journal blocks: 10240
Label: system
Blocks: 655360
Block groups: 20
Reserved block group size: 159
Created filesystem with 2634/163840 inodes and 301781/655360 blocks
[ 99% 87442/87443] Install system fs image: out/target/product/generic_x86_64/system.img
out/target/product/generic_x86_64/system.img+ maxsize=2740556544 blocksize=2112 total=2684354560 reserve=27684096
[100% 87443/87443] Create system-qemu.img
1+0 records in
2048+0 records out
1048576 bytes (1.0 MB, 1.0 MiB) copied, 0.00495976 s, 211 MB/s
2560+0 records in
2560+0 records out
2684354560 bytes (2.7 GB, 2.5 GiB) copied, 15.0664 s, 178 MB/s
1048576+0 records in
1048576+0 records out
1048576 bytes (1.0 MB, 1.0 MiB) copied, 0.709724 s, 1.5 MB/s
Creating new GPT entries.
Warning: The kernel is still using the old partition table.
The new table will be used at the next reboot.
The operation has completed successfully.
Setting name!
partNum is 0
REALLY setting name!
Warning: The kernel is still using the old partition table.
The new table will be used at the next reboot.
The operation has completed successfully.
#### build completed successfully (01:25:40 (hh:mm:ss)) ####
robot@ubuntu:~/aosp81$
六、验证编译结果
source build/envsetup.sh
lunch 6
emulator
至此,使用我们自己编译的android8.1 的内核开发环境就搭建完成。
参考链接: https://harmonyos.51cto.com/posts/7977、 非常感谢作者付出。
|