Android快速编译
Posted 四季帆
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Android快速编译相关的知识,希望对你有一定的参考价值。
1. 获取编译所用的命令和配置
source build/envsetup.sh
lunch xx
make showcommands bootimage >build.log //通过参数showcommands 将编译的命令显示出来
2. 制作编译脚本
touch buld_kernel.sh //创建脚本
复制第三步编译的build.log中 bin/bash -c 开始的每一段到buld_kernel.sh里
在脚本之前加上 source 和 lunch 就可以了
chmod +x buld_kernel.sh //增加可执行全限
./build_kernel.sh //运行编译脚本,以后每次编译使用这个脚本就可以了
3. 高通平台sdm450例子,下面是制作的脚本
source build/envsetup.sh
lunch 19
/bin/bash -c "(if [ ! -z \\"hq_sdm450_defconfig\\" ]; then rm -f ../../out/target/product/hq_sdm450/obj/kernel/msm-4.9/.config; make -j2 -C kernel/msm-4.9 O=../../out/target/product/hq_sdm450/obj/kernel/msm-4.9 DTC_EXT=dtc CONFIG_BUILD_ARM64_DT_OVERLAY=y ARCH=arm64 CROSS_COMPILE=aarch64-linux-android- hq_sdm450_defconfig; make -j2 -C kernel/msm-4.9 O=../../out/target/product/hq_sdm450/obj/kernel/msm-4.9 DTC_EXT=dtc CONFIG_BUILD_ARM64_DT_OVERLAY=y ARCH=arm64 CROSS_COMPILE=aarch64-linux-android- headers_install; if [ -d \\"out/target/product/hq_sdm450/obj/kernel/msm-4.9/usr/include/bringup_headers\\" ]; then cp -Rf out/target/product/hq_sdm450/obj/kernel/msm-4.9/usr/include/bringup_headers/* out/target/product/hq_sdm450/obj/kernel/msm-4.9/usr/include/ ; fi ; fi ) && (if [ \\"hq_sdm450_defconfig\\" != \\"hq_sdm450_defconfig\\" ]; then echo \\"Used a different defconfig for header generation\\"; rm -f ../../out/target/product/hq_sdm450/obj/kernel/msm-4.9/.config; make -j2 -C kernel/msm-4.9 O=../../out/target/product/hq_sdm450/obj/kernel/msm-4.9 DTC_EXT=dtc CONFIG_BUILD_ARM64_DT_OVERLAY=y ARCH=arm64 CROSS_COMPILE=aarch64-linux-android- hq_sdm450_defconfig; fi ) && (if [ ! -z \\"\\" ]; then echo \\"Overriding kernel config with ''\\"; echo >> out/target/product/hq_sdm450/obj/kernel/msm-4.9/.config; make -j2 -C kernel/msm-4.9 O=../../out/target/product/hq_sdm450/obj/kernel/msm-4.9 DTC_EXT=dtc CONFIG_BUILD_ARM64_DT_OVERLAY=y ARCH=arm64 CROSS_COMPILE=aarch64-linux-android- oldconfig; fi )"
/bin/bash -c "(rm -rf out/target/product/hq_sdm450/obj/KERNEL_OBJ ) && (ln -s kernel/msm-4.9 out/target/product/hq_sdm450/obj/KERNEL_OBJ )"
/bin/bash -c "(rm -rf out/target/product/hq_sdm450/obj/kernel/msm-4.9/arch/arm64/boot/dts ) && (make -j2 -C kernel/msm-4.9 O=../../out/target/product/hq_sdm450/obj/kernel/msm-4.9 DTC_EXT=dtc CONFIG_BUILD_ARM64_DT_OVERLAY=y ARCH=arm64 CROSS_COMPILE=aarch64-linux-android- KCFLAGS=-mno-android ) && (make -j2 -C kernel/msm-4.9 O=../../out/target/product/hq_sdm450/obj/kernel/msm-4.9 DTC_EXT=dtc CONFIG_BUILD_ARM64_DT_OVERLAY=y ARCH=arm64 CROSS_COMPILE=aarch64-linux-android- KCFLAGS=-mno-android modules ) && (make -j2 -C kernel/msm-4.9 O=../../out/target/product/hq_sdm450/obj/kernel/msm-4.9 INSTALL_MOD_PATH=../../../dlkm INSTALL_MOD_STRIP=1 DTC_EXT=dtc CONFIG_BUILD_ARM64_DT_OVERLAY=y ARCH=arm64 CROSS_COMPILE=aarch64-linux-android- modules_install ) && (mdpath=\\`find out/target/product/hq_sdm450/dlkm/lib/modules -type f -name modules.dep\\`; if [ \\"\\$mdpath\\" != \\"\\" ];then mpath=\\`dirname \\$mdpath\\`; ko=\\`find \\$mpath/kernel -type f -name *.ko\\`; for i in \\$ko; do mv \\$i out/target/product/hq_sdm450/dlkm/lib/modules/; done; fi ) && (mdpath=\\`find out/target/product/hq_sdm450/dlkm/lib/modules -type f -name modules.dep\\`; if [ \\"\\$mdpath\\" != \\"\\" ];then mpath=\\`dirname \\$mdpath\\`; rm -rf \\$mpath; fi )"
/bin/bash -c "(rm -f out/target/product/hq_sdm450/kernel ) && (cp \\"out/target/product/hq_sdm450/obj/kernel/msm-4.9/arch/arm64/boot/Image.gz-dtb\\" \\"out/target/product/hq_sdm450/kernel\\" )"
/bin/bash -c "(out/host/linux-x86/bin/mkbootimg --kernel out/target/product/hq_sdm450/kernel --base 0x80000000 --pagesize 2048 --cmdline \\"console=ttyMSM0,115200,n8 androidboot.console=ttyMSM0 androidboot.hardware=qcom msm_rtb.filter=0x237 ehci-hcd.park=3 lpm_levels.sleep_disabled=1 androidboot.bootdevice=7824900.sdhci earlycon=msm_serial_dm,0x78af000 firmware_class.path=/vendor/firmware_mnt/image androidboot.usbconfigfs=true loop.max_part=7 buildvariant=userdebug\\" --os_version 9 --os_patch_level 2018-10-05 --header_version 1 --output out/target/product/hq_sdm450/boot.img ) && (size=\\$(for i in out/target/product/hq_sdm450/boot.img; do stat --format \\"%s\\" \\"\\$i\\" | tr -d '\\\\n'; echo +; done; echo 0); total=\\$(( \\$( echo \\"\\$size\\" ) )); printname=\\$(echo -n \\"out/target/product/hq_sdm450/boot.img\\" | tr \\" \\" +); maxsize=\\$(( 0x04000000-69632)); if [ \\"\\$total\\" -gt \\"\\$maxsize\\" ]; then echo \\"error: \\$printname too large (\\$total > \\$maxsize)\\"; false; elif [ \\"\\$total\\" -gt \\$((maxsize - 32768)) ]; then echo \\"WARNING: \\$printname approaching size limit (\\$total now; limit \\$maxsize)\\"; fi ) && (out/host/linux-x86/bin/avbtool add_hash_footer --image out/target/product/hq_sdm450/boot.img --partition_size 0x04000000 --partition_name boot )"
以上是关于Android快速编译的主要内容,如果未能解决你的问题,请参考以下文章
错误记录Android Studio 编译报错 ( Could not determine java version from ‘11.0.8‘. | Android Studio 降级 )(代码片段
Android课程---Android Studio使用小技巧:提取方法代码片段