Android 使用ninja加速编译的方法

ninja的简介

随着Android版本的更迭,makefile体系逐渐增多,导致make单编模块的时间越来越长,每次都需要半个小时甚至更长时间,其原因为每次make都会重新加载所有mk文件,再生成ninja编译,此完整过程十分耗时,实际编译代码仅占其中的一小部分。

因此我们可以使用google提供的一种快速编译方式:ninja,使用ninja编译,基本上十几秒就能快速编完一个模块,但必须注意ninja编译不会重新加载mk文件,故只适用于修改已存在的代码文件的情况,如果涉及到文件的增减、目录的重构就必须用mm/make重新编译之后,才能使用ninja快速编译新的修改。

第一步:进行一次完整编译

source build/envsetup.sh

lunch xxxx-userdebug

./build.sh --dist

(或者make -j24)

第二步:使用ninja进行编译

source build/envsetup.sh

lunch xxxx-userdebug

prebuilts/build-tools/linux-x86/bin/ninja -f out/combined-xxxx.ninja <module_name> -j24

其中module_name为模块名或镜像名:bootimage、dtboimage、framework、Settings等

理论上所有的Makefile或者Android.mk中的module_name皆可使用ninja进行快速编译

举例如下:

prebuilts/build-tools/linux-x86/bin/ninja -f out/combined-sm6150.ninja bootimage -j24

prebuilts/build-tools/linux-x86/bin/ninja -f out/combined-sm6150.ninja dtboimage -j24

prebuilts/build-tools/linux-x86/bin/ninja -f out/combined-sm6150.ninja sepolicy -j24

prebuilts/build-tools/linux-x86/bin/ninja -f out/combined-sm6150.ninja Settings -j24

prebuilts/build-tools/linux-x86/bin/ninja -f out/combined-sm6150.ninja framework -j24

其他常用命令

printconfig -- 打印当前配置清单(lunch xxx)

make bootimage -j16

make module_name -j16

m 编译从根目录开始的所有module

mm 进到module目录进行编译,目录下要有Android.mk

mmm 加指定的路径参数,指定目录下要有Android.mk

croot -- cd to the top of the tree

make clean-<module_name> 例如:make clean-libutils、make clean-charger

make clean 删除out目录

Android 使用ninja加速编译的方法_ninja编译-CSDN博客

相关推荐
CV资深专家3 小时前
在 Android 框架中,接口的可见性规则
android
daifgFuture7 小时前
Android 3D球形水平圆形旋转,旋转动态更换图片
android·3d
二流小码农8 小时前
鸿蒙开发:loading动画的几种实现方式
android·ios·harmonyos
爱吃西红柿!9 小时前
fastadmin fildList 动态下拉框默认选中
android·前端·javascript
悠哉清闲10 小时前
工厂模式与多态结合
android·java
大耳猫11 小时前
Android SharedFlow 详解
android·kotlin·sharedflow
火柴就是我11 小时前
升级 Android Studio 后报错 Error loading build artifacts from redirect.txt
android
androidwork12 小时前
掌握 MotionLayout:交互动画开发
android·kotlin·交互
奔跑吧 android12 小时前
【android bluetooth 协议分析 14】【HFP详解 1】【案例一: 手机侧显示来电,但车机侧没有显示来电: 讲解AT+CLCC命令】
android·hfp·aosp13·telecom·ag·hf·headsetclient
Chenyu_31013 小时前
09.MySQL内外连接
android·数据库·mysql