首页 > 编程知识 正文

基于aosp开发就是基于安卓吗,Android aosp

时间:2023-05-06 19:22:04 阅读:224994 作者:4383

安卓源码AOSP下载使用的正确姿势

从同步源码到编译完成,整个过程应至少准备200G空间。

编译时需要的内存数与编译线程数相关,博主实测比较极限的配置是4核8G,超过这个范围将触发swap交换导致编译速度急剧下降。

开始搞,注:以下*号所有内容替换成G00gle,至于为什么连单词都写错了你懂的。

0x01 前置准备

# 下载reposudo apt-get install repo# 下载git并设置用户名邮箱sudo apt-get install gitgit config --global user.name "bryan sun"git config --global user.email "hitsjt@gmail.com"# 挑选需要同步的AOSP分支https://source.android.*.cn/setup/build-numbers# 配置全局git加速git config --global url.https://mirrors.tuna.tsinghua.edu.cn/git/AOSP/.insteadof https://android.*source.comgit config --global url."https://hub.fastgit.org".insteadOf https://github.com# 取消全局配置# git config --global --unset http.proxy# 三行科普repo是个什么东西当有了版本控制思想,你用上了git。aosp由几百个git子项目组成,如果需要每个子项目都让你手动去挑选版本分支,然后git pull估计得崩溃。repo作为git的控制封装脚本,可以对每个安卓分支版本需要搭配什么git子项目进行列表配置,随后批量操作这些git子项目,这就是为什么*设计了repo,一切为了操作便捷。*在同步源码时查看文件.repo/manifests/default.xml能更好体会# 一把安装环境sudo apt-get install 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 lib32z-dev ccache libgl1-mesa-dev libxml2-utils xsltproc unzip m4 bc -ysudo apt-get install bc bison build-essential ccache curl flex g++-multilib gcc-multilib git gnupg gperf imagemagick lib32ncurses5-dev lib32readline-dev lib32z1-dev liblz4-tool libncurses5-dev libsdl1.2-dev libssl-dev libxml2 libxml2-utils lzop pngcrush rsync schedtool squashfs-tools xsltproc zip zlib1g-dev -y# oracle jdk8# https://www.oracle.com/java/technologies/javase/javase-jdk8-downloads.htmlupdate-alternatives --install /usr/现代的黑裤/java java /usr/lib/jvm/jdk1.8.0_271/现代的黑裤/java 180271update-alternatives --install /usr/现代的黑裤/javac javac /usr/lib/jvm/jdk1.8.0_271/现代的黑裤/javac 180271update-alternatives --install /usr/现代的黑裤/javadoc javadoc /usr/lib/jvm/jdk1.8.0_271/现代的黑裤/javadoc 180271# openjdk8# https://www.openlogic.com/openjdk-downloads# 链接: https://pan.baidu.com/s/1cNtYW-bbqDEPQf8IGIk0Jw 提取码: ghdv openjdk-8u272# 链接: https://pan.baidu.com/s/1r85kLAipjWZxG9DUaKo7sA 提取码: k9r8 openjdk-8u262update-alternatives --install /usr/现代的黑裤/java java /usr/lib/jvm/openlogic-openjdk-8u272-b10-linux-x64/现代的黑裤/java 180272update-alternatives --install /usr/现代的黑裤/javac javac /usr/lib/jvm/openlogic-openjdk-8u272-b10-linux-x64/现代的黑裤/javac 180272update-alternatives --install /usr/现代的黑裤/javadoc javadoc /usr/lib/jvm/openlogic-openjdk-8u272-b10-linux-x64/现代的黑裤/javadoc 180272# 虚拟机设置,真机不用理会apt-get install open-vm-tools-desktop fuse # 安装vmware-toolsmkdir -p /mnt/hgfs/VMShare # 创建挂载目录/usr/现代的黑裤/vmhgfs-fuse .host:/VMShare /mnt/hgfs/VMShare -o subtype=vmhgfs-fuse,allow_other # 挂载共享目录,host指定的名字就是虚拟机共享目录的名字# 设置开机自动挂载gedit /etc/systemd/system/rc-local.service[Unit] Description=/etc/rc.local Compatibility ConditionPathExists=/etc/rc.local[Service] Type=forking ExecStart=/etc/rc.local start TimeoutSec=0 StandardOutput=tty RemainAfterExit=yes SysVStartPriority=99[Install] WantedBy=multi-user.targetgedit /etc/rc.local#!/现代的黑裤/bash# THIS FILE IS ADDED FOR COMPATIBILITY PURPOSES## It is highly advisable to create own systemd services or udev rules# to run scripts during boot instead of using this file.## In contrast to previous versions due to parallel execution during boot# this script will NOT be run after all other services.## Please note that you must run 'chmod +x /etc/rc.d/rc.local' to ensure# that this script will be executed during boot.sudo /usr/现代的黑裤/vmhgfs-fuse .host:/VMShare /mnt/hgfs/VMShare -o subtype=vmhgfs-fuse,allow_otherexit 0chmod 755 /etc/rc.local # 设置执行权限systemctl enable rc-local.service # 开启rc.local开机自启动服务systemctl is-active rc-local.service # 查看服务状态systemctl restart rc-local.service # 重启服务

0x02 获取AOSP源码包

# 方法1.通过下载TUNA完整增量月包,下载完后解压只需要简单操作就能获得大部分源码,剩下的同步只需要少量操作即可完成# 博主未完整实测,下一半挂了,逼着用完整同步https://mirrors.tuna.tsinghua.edu.cn/aosp-monthly/aosp-latest.tarhttps://mirrors.tuna.tsinghua.edu.cn/aosp-monthly/aosp-latest.tar.md5# 解压后得到.repo文件夹,在根目录repo sync即可迁出文件# 如果repo sync操作出现源代码被改动提示可以用以下命令修复repo sync -d # 将所有git 仓库的HEAD重置为manifest文件的指定版本repo forall -c 'git reset --hard' # Remove all working directory (and staged) changes.repo forall -c 'git clean -f -d' # Clean untracked files# 方法2.同步完整的源码repo init -u https://aosp.tuna.tsinghua.edu.cn/platform/manifest --repo-url=https://mirrors.tuna.tsinghua.edu.cn/git/git-repo/ -b android-8.1.0_r15# 开始同步repo sync -c -f --no-tags --no-clone-bundle -j4-c 或者--current-branch表示只拉取当前分支代码,坑爹啊,我在init指定了分支,同步的时候,你却悄悄给我拉些没用的。--no-tags 不拉取tags,tag虽然不大,但架不住多--no-clone-bundle 不使用clone.bundle,clone.bundle是git bundle一样的打包文件,使用bundle文件可以做cdn下载的分流,cdn听上去不错,但是如果cdn到google的服务器,或者clone.bundle本来就占空间,不是很划算,所以不使用clone.bundle-f 如果sync失败,继续同步--force-sync 如果文件目录有差异,强制覆盖掉# 附赠一个git只克隆当前分支的办法,和指定分支无关的部分将不会克隆git clone -b mybranch --single-branch git://sub.domain.com/repo.git# 使用7z最高压缩比打包源码7za a -t7z -m0=lzma -mx=9 -mfb=64 -md=32m -ms=on yourfile.7z yourfile &

0x03 切换不同版本的AOSP

# 将repo配置重新指定为相关版本repo init -u https://aosp.tuna.tsinghua.edu.cn/platform/manifest --repo-url=https://mirrors.tuna.tsinghua.edu.cn/git/git-repo/ -b android-6.0.1_r67# rm -rf有个特性不会删除隐藏目录,切换版本操作也就是只需要保留.repo目录rm -rf *# 再次同步即可repo sync# 查看分支列表cd .repo/manifestsgit branch -av# 其中分支代码也可以在这里查https://blog.csdn.net/bt_leo/article/details/78706608

0x04 编译模拟器版本aosp并用模拟器测试

# 基于android6.0.1, Ubuntu 16.04 LTS# 安装openjdk7,oracle java7不能被aosp识别所以不用sudo add-apt-repository ppa:openjdk-r/ppa# 20200419再次使用发现执行失败,进而Error: retrieving gpg key timed out.# 然后通过你懂的方式上网就行了,Ubuntu这年头都能墙,某网部你牛逼sudo apt-get updatesudo apt-get install openjdk-7-jdk // OpenJdk 7安装# 跳过CCLANG的一个不兼容选项,博主实际编译也遇到过# 如果不修改的话会在编译libart.so的时候error停下。修改 art/build/Android.common_build.mk 文件,定位到77行将:ART_HOST_CLANG := true改为:ART_HOST_CLANG := false# 设置高速编译启用标志位(占硬盘,空间小可以不执行,空间换时间)echo export USE_CCACHE=1 >> ~/.bashrcaosp/prebuilts/misc/linux-x86/ccache/ccache -M 50G# 导入编译环境source build/envsetup.sh# 设置编译选项# lunch aosp_sailfish-userlunch# 开干,-j参数为编译线程数,幸运的话睡一觉起来就OK啦。sudo make -j4# 一键设置环境变量(该命令由build/envsetup.sh导入)set_stuff_for_environment# 进入安卓源码编译生成目录cd out/target/product/generic# 启动模拟器emulator

0x05 编译真机并刷入

# 在官方下载驱动组件包,放在安卓源码根目录解压后运行sh脚本即可,其他流程与普通编译一致https://developers.*.com/android/drivers# 设置最终ROM包的编译签名为releasehttps://source.android.com/devices/tech/ota/sign_buildsgedit build/make/core/MakefileBUILD_KEYS := release-keys# 刷机export ANDROID_PRODUCT_OUT=/root/Desktop/aosp/android10.0_r17.QP1A.191005.007.A3/out/target/product/sailfishfastboot flashall -w

0x06 集成opengapps

# 为了在AOSP上能使用G* Play,可以选择直接集成opengapps,这样编译后刷入就能有套装# 官方已给详细步骤说明,不再另外单独记录# 值得一说的是各设备的配置文件路径会稍有差别,例如pixel在安卓10下路径为device/google/marlin/device-sailfish.mkhttps://github.com/opengapps/aosp_build# Product cannot have overlay in vendor tree# gedit device/lge/bullhead/aosp_bullhead.mk# PRODUCT_RESTRICT_VENDOR_FILES := false

 

参考资料

https://blog.csdn.net/fuchaosz/article/details/51487585

https://mirrors.tuna.tsinghua.edu.cn/help/AOSP/

https://blog.csdn.net/counsellor/article/details/86591081

 

margin

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。