EN

loading
耗时大半年,开源一本 Android 电子书《Android 技术内幕:系统机制、性能优化与工具实战》

Android 内部机制的资料,网上不缺。AOSP、官方文档、博客、论文、trace 讨论,想找都找得到。麻烦的是各说各的版本:这篇是 Android 12 的结论,那篇没写版本,再一篇是某台机器上的现象。

AIW 想补的就是这个缺口。全称 Android Internal Wiki,中文书名是《Android 技术内幕:系统机制、性能优化与工具实战》,五部分二十六章,正文钉在 Android 17。仓库现已公开:

https://github.com/Gracker/android-internals-wiki

打开仓库能拿到的是二十六章正文、一份完整目录,和每周编一次的 EPUB。

这二十六章现在到了可以拿出来给人读的程度。读到哪一段和源码对不上,欢迎提 issue 或者 PR。

Techniques, Philosophy, and Tools for Android Performance Optimization

黑客与画家

In his book Hackers & Painters, Paul Graham asserted, “The disparity in the efficiency of languages is becoming more pronounced, hence the rising importance of profilers. Currently, performance analysis isn’t given the attention it deserves. Many still seem to hold onto the belief that the key to accelerating program execution lies in developing compilers that generate faster code. As the gap between code efficiency and machine performance widens, it will become increasingly apparent that enhancing the execution speed of application software hinges on having a good profiler to guide program development.” by Paul Graham, Hackers & Painters

Search for “Android optimization tools” and you’ll find plenty of articles. Many repeat the same material or go straight to instructions without explaining how the tools fit together. It is easy to come away thinking one tool can solve everything. Our team’s experience says otherwise: there is no silver bullet. Tools change, and familiar problems return in new forms. You still need to understand what is happening underneath.

We’ll start with the data we collect, how we collect it, and how we analyze it. Then we’ll look at Google’s traditional “big three” performance tools. We want you to understand the measurements as well as the tools, and save yourself some of the detours others have already taken.

Android 性能优化的术、道、器

黑客与画家

Paul Graham 在其著作 <黑客与画家> 中断言:“不同语言的执行效率差距正变得越来越大,所以性能分析器(profiler)将变得越来越重要。目前,性能分析并没有受到重视。许多人好像仍然相信,程序运行速度提升的关键在于开发出能够生成更快速代码的编译器。代码效率与机器性能的差距正在不断加大,我们将会越来越清楚地看到,应用软件运行速度提升的关键在于有一个好的性能分析器帮助指导程序开发。”
by Paul Graham 黑客与画家

谷歌搜索 「Android 优化工具」,你会找到很多与此相关的内容。他们的问题在于要么是内容高度重复、要么是直接讲使用方法,很少会给你介绍整体性的架构,一不小心就会让人会种「一个工具搞定一切」的错误认知。以笔者团队的多年经验来看,在性能分析领域这种银弹级别的工具是不存在的。工具在发展,老问题会以新的方式变样出现,不掌握核心逻辑的话始终会让你浮于技术的表面。

本文首先系统性的梳理性能分析中的可观测性技术,它涵盖数据类型、抓取方法以及分析方法等三部分内容,之后是介绍谷歌提供的传统「三大件」分析工具。目的是想让你了解数据与测量的基本概念,以及与之对应的在安卓环境中可用的工具,这些可以让你少走一些弯路,直接复用前辈们的经验。

Android 中的“后台无效动画“行为分析

这篇文章记录的是 2019 年遇到的后台动画问题:应用界面不可见了,进程里却仍有动画工作在执行。但是当用户知道一个 App 退到后台之后还在持续做无效的动画,而这个动画完全是无意义的,而且用户还不知道他在做动画,消耗用户那可怜的电量的时候,轻则被多任务杀掉,禁止后台运行,重则直接卸载。

这个问题容易被忽略。当时我使用 Systrace ,在多开应用后退回桌面,左右滑动并抓取 Systrace ,发现部分已离开的应用仍在频繁执行动画回调。复查时应固定操作和应用版本,并记录界面可见性,不能把“打开很多应用”当成必要或充分条件。

这里讨论的是界面已不可见、业务也不再需要,却仍持续推进的动画。它会增加不必要的工作;但进程还活着不等于能无限制使用 CPU,现代系统还可能冻结 cached 进程。往 Choreographer 提交动画回调的入口很多,最终要结合具体调用栈、播放状态和库版本定位,不能仅凭一个 animation slice 判定原因

Android 系统开发源码环境搭建
不管是 Android App 开发工程师还是 Android 系统开发工程师,对 Android 系统有一定的了解是很有必要的,正好我这几天在家里搭建了个开发环境,把过程分享出来,有需要的人可以看一下。 大概的步骤包含下面几个: 安装 Ubuntu 系统 配置 Ubuntu 系统 安装必备的软件 配置网络访问环境 (可选) 下载 AOSP 代码 配置编译环境并编译 Pixel 的代码 刷机 修改和编译 Framework 、Service、Res 版本说明(2026-10-13 核查):原文是 2018 年的环境记录。截图可见 Ubuntu 18.04.1、PLATFORM_VE...