编译android 源代码 时间,Android编译使用ccache减少编译时间

第1步:安装ccache工具

在Android源代码目录prebuilts/misc/linux-x86/ccache下面有ccache工具的源代码包拷出来(建议根目录),把它解压,然后参考里面的INSTALL.txt文档。操作如下命令(进入到解压的文件里面执行):

./configure

make

sudo  make  install

第2步:配置ccache环境

在~/.bashrc中添加(或者/etc/profile文件中):

export USE_CCACHE=1

export CCACHE_DIR=//.ccache

默认情况下cache(缓存)会保存在~/.ccache目录下,如果主目录位于NFS或其他非本地文件系统上, 设置cache目录位置:

export CCACHE_DIR=

注:配置.bashrc后注意source改文件,否则cache(缓存)会保存在~/.ccache目录下,而不是你设置的目录。

第3步: 使用Android源码prebuilts目录下面的ccache工具初始化该文件夹

推荐的cache目录大小为50-100GB,在命令行执行以下命令:

prebuilts/misc/linux-x86/ccache/ccache -M 50G

注:以上命令需要在你所下载的代码的根目录下面执行

该设置会保存到CCACHE_DIR中,且该命令是长效的,不会因系统重启而失效。使用ccache第一次编译后能够明显提高make clean以后再次的编译速度。使用ccache之后,第一次编译会时间久一点,之后每次编译速度都会有提升,降低所有使用gcc的编译时间,大约25%~30%。

第4步:你可以查看ccahe使用情况,看看上面的设置是否有效

ccache  -s

注:可以通过ccache -s查看cache信息,如果满了可以用ccache -C清除所有。在满了状态下编译新codebase,将会旧的那个清除,这会降低效率,所以cache一定要设置正确!

第5步:开启kernel ccache

(1). 以上ccache只对编译android有效,kernel部分需要额外设置才行

(2). 找到alps/kernel/Makefile文件中的

AS      = $(CROSS_COMPILE)as

LD      = $(CROSS_COMPILE)ld

CC      = $(CROSS_COMPILE)gcc

CPP    = $(CC) -E

之后添加如下代码:

ifneq ($(USE_CCACHE),)

export CCACHE_COMPILERCHECK := content

export CCACHE_SLOPPINESS := time_macros,include_file_mtime,file_macro

export CCACHE_BASEDIR := /

ccache := $(strip $(wildcard $(PWD)/../prebuilts/misc/linux-x86/ccache/ccache))

ifdef ccache

ifneq ($(ccache),$(firstword $(CC)))

CC := $(ccache) $(CC)

endif

ccache =

endif

endif

(3). 这样在编译kernel时也可以享受到ccache带来编译时间的缩短。

以上方法优化后大约可降低50%的编译时间,也就是说优化前需要1小时编译时间,优化后半小时就完成了。

第6步: 共享ccache的缓存 (不共享的话忽略此步)

所有需要共享的用户请添加以下环境变量:

export CCACHE_DIR=

exportCACHE_UMASK=002

unsetCCACHE_HARDLINK

可以将以上添加到$HOME/.bashrc,保证打开的终端都已经加载以上的环境变量。其中< ccache缓存路径 >请替换为指定的绝对路径(必须是需要共享的用户都能读写的)。比如:/proj/.ccache

注意:由于多人同时写ccache缓存可能引起IO带宽不够反而降低效率,强烈建议服务器编译可以此配置,但是其他共享用户最好增加下面配置, 仅只读缓存内容。

export CCACHE_READONLY=1

设置好环境变量后,重新登入终端使环境变量生效,然后创建< ccache缓存路径 >,设置< ccache缓存路径 >的共享权限,在终端输入:

find $CCACHE_DIR -type d | xargs chmod g+s

完成前面的步骤后,就可以开始共享使用了,注意ccache空间要足够大,否则反而拉长编译时间。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Building on: linux-g++ (x86_64, CPU features: mmx sse sse2) Building for: linux-aarch64-gnu-g++ (arm64, CPU features: neon) Target compiler: gcc 6.3.1 Configuration: cross_compile use_gold_linker compile_examples enable_new_dtags largefile neon precompile_header shared rpath release c++11 c++14 concurrent dbus reduce_exports stl Build options: Mode ................................... release Optimize release build for size ........ no Building shared libraries .............. yes Using C standard ....................... C11 Using C++ standard ..................... C++14 Using ccache ........................... no Using gold linker ...................... yes Using new DTAGS ........................ yes Using precompiled headers .............. yes Using LTCG ............................. no Target compiler supports: NEON ................................. yes Build parts ............................ libs Qt modules and options: Qt Concurrent .......................... yes Qt D-Bus ............................... yes Qt D-Bus directly linked to libdbus .... no Qt Gui ................................. yes Qt Network ............................. yes Qt Sql ................................. yes Qt Testlib ............................. yes Qt Widgets ............................. yes Qt Xml ................................. yes Support enabled for: Using pkg-config ....................... yes udev ................................... no Using system zlib ...................... yes Qt Core: DoubleConversion ....................... yes Using system DoubleConversion ........ no GLib ................................... no iconv .................................. yes ICU .................................... no Tracing backend ........................ Logging backends: journald ............................. no syslog ............................... no slog2 ................................ no Using system PCRE2 ..................... no Qt Network: getifaddrs() ........................... yes IPv6 ifname ............................ yes libproxy ............................... no Linux AF_NETLINK ....................... yes OpenSSL ................................ yes Qt directly linked to OpenSSL ........ no OpenSSL 1.1 ............................ no DTLS ................................... yes SCTP ................................... no Use system proxies ..................... yes Qt Gui: Accessibility .......................... yes FreeType ............................... yes Using system FreeType ................ no HarfBuzz ............................... yes Using system HarfBuzz ................ no Fontconfig ............................. no Image formats: GIF .................................. yes ICO .................................. yes JPEG ................................. yes Using system libjpeg ............... yes PNG .................................. yes Using system libpng ................ no EGL .................................... no OpenVG ................................. no OpenGL: Desktop OpenGL ....................... no OpenGL ES 2.0 ........................ no OpenGL ES 3.0 ........................ no OpenGL ES 3.1 ........................ no OpenGL ES 3.2 ........................ no Vulkan ................................. no Session Management ..................... yes Features used by QPA backends: evdev .................................. yes libinput ............................... no INTEGRITY HID .......................... no mtdev .................................. no tslib .................................. no xkbcommon .............................. no X11 specific: XLib ................................. no EGL on X11 ........................... no QPA backends: DirectFB ............................... no EGLFS .................................. no LinuxFB ................................ yes VNC .................................... yes Mir client ............................. no Qt Sql: SQL item models ........................ yes Qt Widgets: GTK+ ................................... no Styles ................................. Fusion Windows Qt PrintSupport: CUPS ................................... no Qt Sql Drivers: DB2 (IBM) .............................. no InterBase .............................. no MySql .................................. no OCI (Oracle) ........................... no ODBC ................................... no PostgreSQL ............................. no SQLite2 ................................ no SQLite ................................. yes Using system provided SQLite ......... no TDS (Sybase) ........................... no Qt Testlib: Tester for item models ................. yes Qt SerialBus: Socket CAN ............................. yes Socket CAN FD .......................... yes Qt QML: QML network support .................... yes QML debugging and profiling support .... yes QML sequence object .................... yes QML list model ......................... yes QML XML http request ................... yes QML Locale ............................. yes QML delegate model ..................... yes Qt Quick: Direct3D 12 ............................ no AnimatedImage item ..................... yes Canvas item ............................ yes Support for Qt Quick Designer .......... yes Flipable item .......................... yes GridView item .......................... yes ListView item .......................... yes TableView item ......................... yes Path support ........................... yes PathView item .......................... yes Positioner items ....................... yes Repeater item .......................... yes ShaderEffect item ...................... yes Sprite item ............................ yes Qt Scxml: ECMAScript data model for QtScxml ...... yes Qt Gamepad: SDL2 ................................... no Qt 3D: Assimp ................................. yes System Assimp .......................... no Output Qt3D Job traces ................. no Output Qt3D GL traces .................. no Use SSE2 instructions .................. no Use AVX2 instructions .................. no Aspects: Render aspect ........................ yes Input aspect ......................... yes Logic aspect ......................... yes Animation aspect ..................... yes Extras aspect ........................ yes Qt 3D Renderers: OpenGL Renderer ........................ yes Qt 3D GeometryLoaders: Autodesk FBX ........................... no Qt Wayland Client ........................ no Qt Wayland Compositor .................... no Qt Bluetooth: BlueZ .................................. no BlueZ Low Energy ....................... no Linux Crypto API ....................... no WinRT Bluetooth API (desktop & UWP) .... no Qt Sensors: sensorfw ............................... no Qt Quick Controls 2: Styles ................................. Default Fusion Imagine Material Universal Qt Quick Templates 2: Hover support .......................... yes Multi-touch support .................... yes Qt Positioning: Gypsy GPS Daemon ....................... no WinRT Geolocation API .................. no Qt Location: Qt.labs.location experimental QML plugin . yes Geoservice plugins: OpenStreetMap ........................ yes HERE ................................. yes Esri ................................. yes Mapbox ............................... yes MapboxGL ............................. no Itemsoverlay ......................... yes QtXmlPatterns: XML schema support ..................... yes Qt Multimedia: ALSA ................................... no GStreamer 1.0 .......................... no GStreamer 0.10 ......................... no Video for Linux ........................ yes OpenAL ................................. no PulseAudio ............................. no Resource Policy (libresourceqt5) ....... no Windows Audio Services ................. no DirectShow ............................. no Windows Media Foundation ............... no Qt Tools: QDoc ................................... no Qt WebEngine: Embedded build ......................... yes Pepper Plugins ......................... no Printing and PDF ....................... no Proprietary Codecs ..................... no Spellchecker ........................... yes Native Spellchecker .................... no WebRTC ................................. no Use System Ninja ....................... no Geolocation ............................ yes WebChannel support ..................... yes Use v8 snapshot ........................ yes Kerberos Authentication ................ no Building v8 snapshot supported ......... yes Use ALSA ............................... no Use PulseAudio ......................... no Optional system libraries used: re2 .................................. no icu .................................. no libwebp, libwebpmux and libwebpdemux . no opus ................................. no ffmpeg ............................... no libvpx ............................... no snappy ............................... no glib ................................. no zlib ................................. yes minizip .............................. no libevent ............................. no jsoncpp .............................. no protobuf ............................. no libxml2 and libxslt .................. no lcms2 ................................ no png .................................. no JPEG ................................. no harfbuzz ............................. no freetype ............................. no x11 .................................. no Required system libraries: fontconfig ........................... no dbus ................................. no nss .................................. no khr .................................. no glibc ................................ yes Required system libraries for qpa-xcb: libdrm ............................... no xcomposite ........................... no xcursor .............................. no xi ................................... no xrandr ............................... no xtst ................................. no Note: Also available for Linux: linux-clang linux-icc

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值