首页 > 系统 > Android > 正文

Android官方资料--Reducing OTA Size

2019-11-09 15:37:14
字体:
来源:转载
供稿:网友

Reducing OTA Size

IN THIS DOCUMENT

The build diff toolChanges to reduce OTA sizeFile OrderBuild DirectoryTimestampsVersion StringsConsistent build tools

A common PRoblem with Android over-the-air updates (OTAs) is that they contain changed files that do not correspond to code changes, but instead are artifacts of the build system. This happens whenever the same code, built at different times, from different directories, or on different machines, produces a large number of changed files. The excess files not only increase the size of an OTA, but make it difficult to determine which code is changed in the OTA.

To make the contents of an OTA more transparent, we have added a number of build system changes that reduce the size of an OTA by eliminating unnecessary file changes between builds. The aim is to reduce the size of OTAs to include only the files that relate to the patches contained in the OTA. We have also introduced a build diff tool that filters out common build-related file changes and provides a cleaner build file diff (see below).

This document provides an explanation of some of the build changes that have been added to AOSP to reduce unnecessary file changes between builds. For device implementers who maintain their own build system, it provides a guide to some of the changes that need to be made to reduce OTA size.

The build diff tool

Since there are cases where it is not possible to eliminate build-related file changes, we have supplied a build diff tool, target_files_diff.py, that can be used to compare two target file packages.

The build diff tool does a recursive diff between two builds, excluding common build-related file changes. Excluded changes include the following:

Expected changes in the build output (for example, due to build number changing).Changes due to known issues in the current build system.

To use the build diff tool, run the following command:

$ target_files_diff.py dir1 dir2

where dir1 and dir2 are base directories that contain the extracted target files for each build.

Changes to reduce OTA size


There are several ways that the build system can create unnecessary file diffs. In the following sections, we discuss some of these issues, discuss solutions, and, where possible, show examples of the fixes in AOSP.

File Order

Problem: Filesystems don’t guarantee a file order when asked for a list of files in a directory, though it’s commonly the same for the same checkout. Tools such as ls sort the results by default, but the wildcard function used by commands such as find and make do not. So when any of these tools are used, you need to sort the outputs before using them.

Solution: Users of tools such as find and make with wildcard need to sort the output of these commands before using them. In fact, any uses of $(wildcard ) or $(shell find ) in Android.mk files should be sorted. (Some tools (like java) will sort their inputs, so in some cases it may not actually necessary.)

Examples: Many instances of this were fixed in the core build system, especially when you use the builtin all-*-files-under macros (and all-cpp-files-under was added, since there were several definitions spread out in other makefiles):

https://android.googlesource.com/platform/build/+/4d66adfd0e6d599d8502007e4ea9aaf82e95569fhttps://android.googlesource.com/platform/build/+/379f9f9cec4fe1c66b6d60a6c19fecb81b9eb410https://android.googlesource.com/platform/build/+/7c3e3f8314eec2c053012dd97d2ae649ebeb5653https://android.googlesource.com/platform/build/+/5c64b4e81c1331cab56d8a8c201f26bb263b630c

Build Directory

Problem: Changing the directory in which things are built can cause the binaries to be different. Most paths in the android build are relative paths, so __FILE__ in C/C++ isn’t a problem.

But the debug symbols encode the full pathname by default. Then the .note.gnu.build-id is generated from hashing the pre-stripped binary, so it will change if the debug symbols change.

Solution: To fix this, AOSP master has been changed to make the debug paths relative, as shown here:

https://android.googlesource.com/platform/build/+/6a66a887baadc9eb3d0d60e26f748b8453e27a02

Timestamps

Problem: Timestamps in the build output result in unnecessary file changes. Two places this is likely to happen are the following:

__DATE__/__TIME__/__TIMESTAMP__ macros in C or C++ code.Timestamps embedded in zip-based archives.

Solutions/Examples:

To remove timestamps from the build output in each of these instances, see the instructions in the sections below.

__DATE__/__TIME__/__TIMESTAMP__ in C/C++

These macros always produce different outputs for different builds, so they shouldn’t be used.

Here are a few options on how to eliminate these macros:

Just remove them, they often aren’t necessary.Example:https://android.googlesource.com/platform/system/core/+/30622bbb209db187f6851e4cf0cdaa147c2fca9fIf you just need to be able to uniquely identify the running binary, read the build-id from the ELF header. (No example, we didn’t run into this problem.)If you just want to know when the OS was built, you can read the ro.build.date -- this should work for everything except incremental builds, which may not update this date.Example:https://android.googlesource.com/platform/external/libChrome/+/8b7977eccc94f6b3a3896cd13b4aeacbfa1e0f84

We have turned on -Werror=date-time, so that using timestamps is a build error.

Embedded Timestamps in Zip-based archives (zip, jar)

We fixed the problem of embedded timestamps in zip archives by adding -X to all uses of the zip command, so that the UID/GID of the builder, and the extended Unix timestamp weren’t embedded in the zip file.

A new tool, ziptime, resets the normal timestamps in the zip headers:

https://android.googlesource.com/platform/build/+/master/tools/ziptime/

For more information, see the README file.

The signapk tool sets timestamps for the APK files that may vary depending on the server timezone. This problems was fixed in the following CL:

https://android.googlesource.com/platform/build/+/6c41036bcf35fe39162b50d27533f0f3bfab3028

Version Strings

Problem: APK version strings often had the BUILD_NUMBER appended to the hardcoded version. So even if nothing else changed in the APK, the APK would still be different.

Solution: Remove the build number from the APK version string.

Examples:

https://android.googlesource.com/platform/packages/apps/Camera2/+/5e0f4cf699a4c7c95e2c38ae3babe6f20c258d27https://android.googlesource.com/platform/build/+/d75d893da8f97a5c7781142aaa7a16cf1dbb669c

Consistent build tools

Problem: Any tools that generate installed files need to be consistent, that is, the same input should always produce the same output.

Solutions/Examples: Changes were required in the following build tools:

NOTICE file creator The NOTICE file creator needed the following changes:https://android.googlesource.com/platform/build/+/8ae4984c2c8009e7a08e2a76b1762c2837ad4f64Java Android Compiler Kit (Jack) The Jack toolchain required an update to handle an occasional change in generated constructor ordering:https://android.googlesource.com/toolchain/jack/+/056a5425b3ef57935206c19ecb198a89221ca64bART AOT compiler (dex2oat)The ART compiler binary required an update to create a deterministic image:https://android.googlesource.com/platform/art/+/ace0dc1dd5480ad458e622085e51583653853fb9The libpac.so file (V8)Every build creates a different /system/lib/libpac.so file, because the V8 snapshot changes for each build. The solution is to remove the snapshot:

https://android.googlesource.com/platform/external/v8/+/e537f38c36600fd0f3026adba6b3f4cbcee1fb29application pre-dexopt’d (.odex) files The pre-dexopt’d (.odex) files contained uninitialized padding on 64-bit systems, requiring the following fix:

https://android.googlesource.com/platform/art/+/34ed3afc41820c72a3c0ab9770be66b6668aa029
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表