Android Q默认不使用ccache编译,以及修改方法

build/core/ccache.mk中有一段注释

# We no longer provide a ccache prebuilt.
#
# Ours was old, and had a number of issues that triggered non-reproducible
# results and other failures. Newer ccache versions may fix some of those
# issues, but at the large scale of our build servers, we weren't seeing
# significant performance gains from using ccache -- you end up needing very
# good locality and/or very large caches if you're building many different
# configurations.
#
# Local no-change full rebuilds were showing better results, but why not just
# use incremental builds at that point?
#
# So if you still want to use ccache, continue setting USE_CCACHE, but also set
# the CCACHE_EXEC environment variable to the path to your ccache executable.

大概意思是aosp中预置的ccache已经太老了,会引起一些意想不到的错误,不建议使用,如果一定要使用的话,可以自己安装最新版本的ccache,然后把ccache的路径添加到环境变量中

export CCACHE_EXEC := /usr/bin/ccache

export USE_CCACHE=true

不过这种export 环境变量的方法我试了好像不起作用,不知道是什么原因,可以直接在 build/core/ccache.mk 文件中添加

CCACHE_EXEC := /usr/bin/ccache,修改之后的文件如下:

#
# Copyright (C) 2015 The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

# We no longer provide a ccache prebuilt.
#
# Ours was old, and had a number of issues that triggered non-reproducible
# results and other failures. Newer ccache versions may fix some of those
# issues, but at the large scale of our build servers, we weren't seeing
# significant performance gains from using ccache -- you end up needing very
# good locality and/or very large caches if you're building many different
# configurations.
#
# Local no-change full rebuilds were showing better results, but why not just
# use incremental builds at that point?
#
# So if you still want to use ccache, continue setting USE_CCACHE, but also set
# the CCACHE_EXEC environment variable to the path to your ccache executable.

# add begin
CCACHE_EXEC := /usr/bin/ccache
# add end

ifneq ($(CCACHE_EXEC),)
ifneq ($(filter-out false,$(USE_CCACHE)),)
  # The default check uses size and modification time, causing false misses
  # since the mtime depends when the repo was checked out
  CCACHE_COMPILERCHECK ?= content

  # See man page, optimizations to get more cache hits
  # implies that __DATE__ and __TIME__ are not critical for functionality.
  # Ignore include file modification time since it will depend on when
  # the repo was checked out
  CCACHE_SLOPPINESS := time_macros,include_file_mtime,file_macro

  # Turn all preprocessor absolute paths into relative paths.
  # Fixes absolute paths in preprocessed source due to use of -g.
  # We don't really use system headers much so the rootdir is
  # fine; ensures these paths are relative for all Android trees
  # on a workstation.
  CCACHE_BASEDIR := /

  # Workaround for ccache with clang.
  # See http://petereisentraut.blogspot.com/2011/09/ccache-and-clang-part-2.html
  CCACHE_CPP2 := true

  ifndef CC_WRAPPER
    CC_WRAPPER := $(CCACHE_EXEC)
  endif
  ifndef CXX_WRAPPER
    CXX_WRAPPER := $(CCACHE_EXEC)
  endif
endif
endif
<think>好的,用户想了解Android源代码的编译过程,步骤和流程。我需要根据提供的引用内容整理出一个清晰的步骤指南。首先,要确定系统环境,可能包括Linux发行版、JDK版本、依赖库等。根据引用[3],用户提到新公司的Linux电脑需要配置环境,所以需要详细列出系统要求,比如Ubuntu版本,安装依赖的命令。 接下来,下载源代码部分。引用[3]提到参考Google官方流程,可能需要用repo工具初始化仓库,同步代码。需要解释repo init和repo sync的使用方法,以及选择分支或标签。 然后是准备编译环境,设置环境变量,比如source build/envsetup.sh,选择lunch目标。这里可能需要说明同lunch选项对应的设备类型,比如aosp_arm-eng,用户可能需要根据实际情况选择。 编译部分,引用[1]和[2]提到编译过程中会遇到很多问题,需要提醒用户注意常见错误,比如内存足、依赖缺失。还要注意是否编译内核,引用[5]指出默认编译内核,除非需要修改驱动,这时候需要单独编译内核。 生成镜像文件后,刷机或运行模拟器。需要解释生成的img文件如何刷入设备,或者使用emulator启动模拟器。可能引用[2]中的刷机步骤,但用户可能只是想知道基本流程,一定需要详细刷机步骤。 最后,常见问题部分要总结引用中提到的各种问题,比如编译中断、资源文件修改后的编译(引用[4]中的framework资源编译),以及如何解决依赖问题。此外,优化编译速度的方法,比如ccache,也是用户可能关心的。 需要确保步骤结构清晰,分点说明,每个步骤包含必要的命令和解释。同时,相关问题要围绕编译流程可能涉及的扩展问题,比如性能优化、内核编译、环境配置等。还要注意用户提到的“尽量保证回答真实可靠”,所以需要基于引用内容,避免猜测。 检查是否遵循了系统级指令,数学公式是否正确,但这个问题可能涉及太多数学内容,主要代码块是命令和脚本。确保所有代码块用反引号包裹,独立公式用$$,但这里可能用上。引用标识要正确添加到对应的位置,比如编译问题引用[1],环境设置引用[3],内核编译引用[5]等。 最后生成相关问题,可能涉及编译优化、常见错误解决、内核编译、环境配置等,确保问题与编译流程相关,帮助用户深入理解。</think>### Android 源码编译步骤及流程 #### 一、系统环境准备 1. **操作系统要求** - 推荐使用 **Ubuntu 18.04/20.04 LTS**(其他 Linux 发行版需适配依赖)[^3]。 - 至少 **16GB 内存**(建议 32GB 以上,否则易出现编译中断)[^1]。 - 磁盘空间需预留 **250GB 以上**(源码 + 编译产物)[^3]。 2. **安装依赖工具** ```bash sudo apt update sudo apt 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 ``` 3. **配置 Java 环境** - Android 7.0 (Nougat) 及以下:OpenJDK 8 - Android 8.0 (Oreo) 及以上:OpenJDK 11 ```bash sudo apt install openjdk-11-jdk ``` --- #### 二、源码下载 1. **初始化 Repo 工具** ```bash mkdir ~/android-source && cd ~/android-source curl https://storage.googleapis.com/git-repo-downloads/repo > repo chmod +x repo ./repo init -u https://android.googlesource.com/platform/manifest -b <分支名> # 如 android-13.0.0_r1 ``` 2. **同步源码** ```bash ./repo sync -j4 # -j 后为并发线程数,根据网络调整 ``` - 若中断可重复执行 `repo sync`[^3]。 --- #### 三、编译环境配置 1. **加载编译脚本** ```bash source build/envsetup.sh ``` 2. **选择编译目标** ```bash lunch # 交互式选择,例如 aosp_arm-eng(模拟器)或具体设备型号 ``` 3. **启用编译缓存(可选)** ```bash export USE_CCACHE=1 ccache -M 50G # 设置缓存大小 ``` --- #### 四、开始编译 1. **全量编译** ```bash make -j$(nproc) # 使用全部 CPU 核心加速 ``` - 若失败,可通过 `m` 或 `mma` 命令局部重编[^2]。 2. **生成镜像文件** - 编译成功后,产物位于 `out/target/product/<设备名>/`,包含 `system.img`, `boot.img` 等[^3]。 --- #### 五、刷机或运行模拟器 1. **刷机到设备** ```bash adb reboot bootloader fastboot flashall -w # 需设备进入 fastboot 模式 ``` 2. **启动模拟器** ```bash emulator # 需提前配置环境变量 ``` --- #### 六、常见问题与解决 1. **编译中断** - **内存足**:减少并发线程数(`make -j4`)[^1]。 - **依赖缺失**:根据报错安装对应库(如 `libssl-dev`)[^1]。 2. **修改 Framework 资源** - 修改后执行 `mm` 或 `mmm frameworks/base` 局部编译[^4]。 3. **编译内核(可选)** ```bash cd kernel/msm # 示例路径 make ARCH=arm64 CROSS_COMPILE=aarch64-linux-android- defconfig make -j$(nproc) ``` - 默认编译包含内核,需手动处理[^5]。 ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值