福州服务类网站建设,社区推广,wordpress cos 配置,免费咨询医生的软件有什么前言
作为Android开发者人人都应该有一份自己Android源码,这样我们就可以随时对自己有疑惑的地方通过亲手调试来加强理解
一 源码下载
1.1 配置要求
官方推荐配置请参考#xff1a;AOSP使用入门文档#xff0c;重点有如下几项#xff1a;
1.1.1 硬件配置要求
至少需要…前言
作为Android开发者人人都应该有一份自己Android源码,这样我们就可以随时对自己有疑惑的地方通过亲手调试来加强理解
一 源码下载
1.1 配置要求
官方推荐配置请参考AOSP使用入门文档重点有如下几项
1.1.1 硬件配置要求
至少需要 250 GB 可用磁盘空间如果要进行构建则还需要 150 GB。如果要进行多次构建则需要更多空间。磁盘至少 250GB实测建议至少 512G。
1.1.2 软件要求
推荐使用 Ubuntu 18.04 (Bionic Beaver)、 Docker、Linux。 2021年6月22日起不再支持 Windows 或 MacOS 上构建。 2020年1月1日起不再支持 python2请使用 python3。
1.2 下载环境搭建
1.2.1 依赖安装
请使用如下命令安装相关依赖
sudo apt-get install git-core gnupg flex bison build-essential zip curl zlib1g-dev libc6-dev-i386 libncurses5 lib32ncurses5-dev x11proto-core-dev libx11-dev lib32z1-dev libgl1-mesa-dev libxml2-utils xsltproc unzip fontconfig执行结果如下
longzhiyelongzhiye-laptop:~$ sudo apt-get install git-core gnupg flex bison build-essential zip curl zlib1g-dev libc6-dev-i386 libncurses5 lib32ncurses5-dev x11proto-core-dev libx11-dev lib32z1-dev libgl1-mesa-dev libxml2-utils xsltproc unzip fontconfig
正在读取软件包列表... 完成
正在分析软件包的依赖关系树
正在读取状态信息... 完成
......
升级了 0 个软件包新安装了 114 个软件包要卸载 0 个软件包有 5 个软件包未被升级。
需要下载 58.6 MB 的归档。
解压缩后会消耗 262 MB 的额外空间。
您希望继续执行吗 [Y/n] y
......
python3 已经是最新版 (3.6.7-1~18.04)。
python3 已设置为手动安装。
下列软件包是自动安装的并且现在不需要了gir1.2-goa-1.0 gir1.2-snapd-1
使用sudo apt autoremove来卸载它(它们)。
升级了 0 个软件包新安装了 0 个软件包要卸载 0 个软件包有 5 个软件包未被升级。1.2.2 git配置
请使用如下命令对git进行配置
git config --global user.name xxx
git config --global user.email xxxxxx.com执行结果如下
longzhiyelongzhiye-laptop:~$ git config --global user.name longzhiye
longzhiyelongzhiye-laptop:~$ git config --global user.email longzhiye163163.com1.2.3 repo配置
由于某墙的原因,这里我们采用国内的镜像源进行下载. 目前,可用的镜像源一般是科大和清华的,具体使用差不多,这里我选择清华大学镜像进行说明.(参考:科大源,清华源)请使用如下命令更新repo并进行配置
mkdir ~/bin
PATH~/bin:$PATH
curl https://mirrors.tuna.tsinghua.edu.cn/git/git-repo ~/bin/repo
chmod x ~/bin/repo执行结果如下
longzhiyelongzhiye-laptop:~$ mkdir ~/bin
longzhiyelongzhiye-laptop:~$ PATH~/bin:$PATH
longzhiyelongzhiye-laptop:~$ curl https://mirrors.tuna.tsinghua.edu.cn/git/git-repo ~/bin/repo% Total % Received % Xferd Average Speed Time Time Time CurrentDload Upload Total Spent Left Speed
100 45805 100 45805 0 0 117k 0 --:--:-- --:--:-- --:--:-- 117k
longzhiyelongzhiye-laptop:~$ chmod x ~/bin/repo1.3 源码下载
1.3.1 明确下载版本
请通过浏览器访问分支列表来选取需要的版本。 网页显示如下
1.3.2 替换为清华源
请使用如下命令将源替换为清华源
export REPO_URLhttps://mirrors.tuna.tsinghua.edu.cn/git/git-repo/执行结果如下
longzhiyelongzhiye-laptop:~$ export REPO_URLhttps://mirrors.tuna.tsinghua.edu.cn/git/git-repo/1.3.3 初始化仓库并指定分支
请使用如下命令初始化仓库并指定分支此处以android-13.0.0_r40分支为例。
repo init -u https://aosp.tuna.tsinghua.edu.cn/platform/manifest -b android-13.0.0_r40执行结果如下
longzhiyelongzhiye-laptop:~/mount/project$ mkdir androidt // 建立下载位置
longzhiyelongzhiye-laptop:~/mount/project$ cd androidt/
longzhiyelongzhiye-laptop:~/mount/project/androidt$ repo init -u https://aosp.tuna.tsinghua.edu.cn/platform/manifest -b android-13.0.0_r40
Downloading Repo source from https://mirrors.tuna.tsinghua.edu.cn/git/git-repo/
remote: Enumerating objects: 4495, done.
remote: Counting objects: 100% (4495/4495), done.
remote: Compressing objects: 100% (2144/2144), done.
remote: Total 8060 (delta 3993), reused 2351 (delta 2351), pack-reused 3565
接收对象中: 100% (8060/8060), 3.81 MiB | 1016.00 KiB/s, 完成.
处理 delta 中: 100% (5177/5177), 完成.
repo: Updating release signing keys to keyset ver 2.3Your identity is: longzhiye longzhiye163163.com
If you want to change this, please re-run repo init with --config-nameTesting colorized output (for repo diff, repo status):black red green yellow blue magenta cyan white bold dim ul reverse
Enable color display in this user account (y/N)? yrepo has been initialized in /home/longzhiye/mount/project/androidt
longzhiyelongzhiye-laptop:~/mount/project/androidt$ ls -al
总用量 12
drwxrwxr-x 3 longzhiye longzhiye 4096 5月 20 00:48 .
drwxrwxrwx 3 root root 4096 5月 20 00:44 ..
drwxrwxr-x 5 longzhiye longzhiye 4096 5月 20 00:48 .repo1.3.4 同步全部源码
初始化仓库之后,就可以开始正式同步代码到本地了,命令如下:
repo sync -c -j8此处为了加快速度使用了-c参数表示只同步当前分支-j8表示使用8个线程今天同步代码使用多少个线程请根据自己的机器配置自行修改。 (提示:一定要确定代码完全同步了,不然在下面编译过程出现的错误会让你痛不欲生,不确定的童鞋可以多用repo sync同步几次)
执行结果如下
longzhiyelongzhiye-laptop:~/mount/project/androidt$ repo sync -c -j8
Fetching: 100% (1135/1135), done in 4h51m48.506s
正在检出文件: 100% (1972/1972), 完成.
正在检出文件: 100% (1787/1787), 完成.
......
正在检出文件: 100% (724/724), 完成.orm/system/keymaster正在检出文件: 73% (534/724)
Checking out: 100% (1135/1135), done in 44m21.860s
repo sync has finished successfully.源码同步时间比较长此时Android13源码已经同步完成。
二 Android源码编译
2.1 编译环境搭建
使用如下命令安装JDK
sudo apt-get install openjdk-11-jdk安装完成后可以使用如下命令查看是否按照成功
longzhiyelongzhiye-laptop:javac -version
javac 11.0.172.2 全编译
2.2.1 初始化编译环境
执行如下命令进行编译环境初始化
source build/envsetup.sh
或者
. build/envsetup.sh执行结果如下
longzhiyelongzhiye-laptop:~/mount/project/androidt$ source build/envsetup.sh2.2.2 选择构建目标
执行lunch命令执行结果如下
longzhiyelongzhiye-laptop:~/mount/project/androidt$ lunchYoure building on LinuxLunch menu .. Here are the common combinations:1. aosp_arm-eng2. aosp_arm64-eng3. aosp_barbet-userdebug4. aosp_bluejay-userdebug5. aosp_bluejay_car-userdebug6. aosp_bramble-userdebug7. aosp_bramble_car-userdebug8. aosp_car_arm-userdebug9. aosp_car_arm64-userdebug10. aosp_car_x86-userdebug11. aosp_car_x86_64-userdebug12. aosp_cf_arm64_auto-userdebug13. aosp_cf_arm64_phone-userdebug14. aosp_cf_x86_64_foldable-userdebug15. aosp_cf_x86_64_pc-userdebug16. aosp_cf_x86_64_phone-userdebug17. aosp_cf_x86_64_tv-userdebug18. aosp_cf_x86_auto-userdebug19. aosp_cf_x86_phone-userdebug20. aosp_cf_x86_tv-userdebug21. aosp_cheetah-userdebug22. aosp_cloudripper-userdebug23. aosp_coral-userdebug24. aosp_coral_car-userdebug25. aosp_flame-userdebug26. aosp_flame_car-userdebug27. aosp_oriole-userdebug28. aosp_oriole_car-userdebug29. aosp_panther-userdebug30. aosp_raven-userdebug31. aosp_raven_car-userdebug32. aosp_ravenclaw-userdebug33. aosp_redfin-userdebug34. aosp_redfin_car-userdebug35. aosp_redfin_vf-userdebug36. aosp_slider-userdebug37. aosp_sunfish-userdebug38. aosp_sunfish_car-userdebug39. aosp_trout_arm64-userdebug40. aosp_trout_x86-userdebug41. aosp_whitefin-userdebug42. aosp_x86-eng43. aosp_x86_64-eng44. arm_krait-eng45. arm_v7_v8-eng46. armv8-eng47. armv8_cortex_a55-eng48. armv8_kryo385-eng49. beagle_x15-userdebug50. beagle_x15_auto-userdebug51. car_ui_portrait-userdebug52. car_x86_64-userdebug53. db845c-userdebug54. gsi_car_arm64-userdebug55. gsi_car_x86_64-userdebug56. hikey-userdebug57. hikey64_only-userdebug58. hikey960-userdebug59. hikey960_tv-userdebug60. hikey_tv-userdebug61. poplar-eng62. poplar-user63. poplar-userdebug64. qemu_trusty_arm64-userdebug65. rb5-userdebug66. sdk_car_arm-userdebug67. sdk_car_arm64-userdebug68. sdk_car_portrait_x86_64-userdebug69. sdk_car_x86-userdebug70. sdk_car_x86_64-userdebug71. sdk_pc_x86_64-userdebug72. silvermont-eng73. uml-userdebug74. yukawa-userdebug75. yukawa_sei510-userdebugWhich would you like? [aosp_arm-eng]
Pick from common choices above (e.g. 13) or specify your own (e.g. aosp_barbet-eng): aosp_arm64-engHint: next time you can simply run lunch aosp_arm64-eng
PLATFORM_VERSION_CODENAMEREL
PLATFORM_VERSION13
TARGET_PRODUCTaosp_arm64
TARGET_BUILD_VARIANTeng
TARGET_BUILD_TYPErelease
TARGET_ARCHarm64
TARGET_ARCH_VARIANTarmv8-a
TARGET_CPU_VARIANTgeneric
TARGET_2ND_ARCHarm
TARGET_2ND_ARCH_VARIANTarmv8-a
TARGET_2ND_CPU_VARIANTgeneric
HOST_ARCHx86_64
HOST_2ND_ARCHx86
HOST_OSlinux
HOST_OS_EXTRALinux-5.4.0-148-generic-x86_64-Ubuntu-18.04.6-LTS
HOST_CROSS_OSwindows
HOST_CROSS_ARCHx86
HOST_CROSS_2ND_ARCHx86_64
HOST_BUILD_TYPErelease
BUILD_IDTQ2A.230405.003.B2
OUT_DIRout
PRODUCT_SOONG_NAMESPACESdevice/generic/goldfish device/generic/goldfish-opengl hardware/google/camera hardware/google/camera/devices/EmulatedCamera中间会有选择需要构建的目标此处以aosp_arm64-eng为例
2.2.3 编译固件
通过make指令进行代码编译,该指令通过-j参数来设置参与编译的线程数量,以提高编译速度.比如这里我们设置8个线程同时编译。需要注意的是,参与编译的线程并不是越多越好,通常是根据你机器cup的核心来确定:core*2,即当前cpu的核心的2倍.比如,我现在的笔记本是双核四线程的,因此根据公式,最快速的编译可以make -j8. (通过cat /proc/cpuinfo查看相关cpu信息)
make -j8执行结果如下
longzhiyelongzhiye-laptop:~/mount/project/androidt$ make -j8
07:04:26 ************************************************************
07:04:26 You are building on a machine with 15.5GB of RAM
07:04:26
07:04:26 The minimum required amount of free memory is around 16GB,
07:04:26 and even with that, some configurations may not work.
07:04:26
07:04:26 If you run into segfaults or other errors, try reducing your
07:04:26 -j value.
07:04:26 ************************************************************
build/make/core/soong_config.mk:209: warning: BOARD_PLAT_PUBLIC_SEPOLICY_DIR has been deprecated. Use SYSTEM_EXT_PUBLIC_SEPOLICY_DIRS instead.
build/make/core/soong_config.mk:210: warning: BOARD_PLAT_PRIVATE_SEPOLICY_DIR has been deprecated. Use SYSTEM_EXT_PRIVATE_SEPOLICY_DIRS instead.PLATFORM_VERSION_CODENAMEREL
......
[ 99% 120038/120059] //frameworks/base/packages/SystemUI:SystemUI-core javac
注: 某些输入文件使用或覆盖了已过时的 API。
注: 有关详细信息, 请使用 -Xlint:deprecation 重新编译。
注: 某些输入文件使用了未经检查或不安全的操作。
注: 有关详细信息, 请使用 -Xlint:unchecked 重新编译。
[ 99% 120044/120059] //frameworks/base/packages/SystemUI:SystemUI r8
Warning: Missing class android.compat.annotation.UnsupportedAppUsage (referenced from: void com.android.systemui.people.widget.PeopleBackupHelper.writeNewStateDescription(android.os.ParcelFileDescriptor))
[100% 120059/120059] Target vbmeta image: out/target/product/generic/vbmeta.img#### build completed successfully (05:56:23 (hh:mm:ss)) ####如果一切顺利的化,在几个小时之后,便可以编译完成.看到### make completed successfully (00:48:15(hh:mm:ss)) ###表示你编译成功了.。Google 使用 72 核机器内置 RAM 为 64 GB完整构建过程大约需要 40 分钟增量构建只需几分钟时间具体取决于修改了哪些文件。相比之下RAM 数量相近的 6 核机器执行完整构建过程需要 3 个小时。
二 运行模拟器
在编译完成之后,就可以通过以下命令运行Android虚拟机了,命令如下:
source build/envsetup.sh
lunch // 选择刚才你设置的目标版本,比如这里了我选择的是2
emulator执行结果如下
longzhiyelongzhiye-laptop:~/mount/project/androidt$ source build/envsetup.sh
longzhiyelongzhiye-laptop:~/mount/project/androidt$ lunch
longzhiyelongzhiye-laptop:~/mount/project/androidt$ emulator不出意外,在等待一会之后,你会看到运行界面