Optimizing Android build performance

3 minute read

This section describes the best practices for running Android builds.

For the fastest Android builds, you should have at least 16 agents.

Minimum RAM requirements for agent hosts

The minimum recommended total amount of RAM for an agent host is at least 2 GB per agent plus the amount of RAM normally needed by your build. For example, if you run four agents and your build normally needs 16 GB, you need ((2 * 4) + 16) = 24 GB.

Required installed packages

The patch utility is required. This is supplied by the Linux distribution in a package named patch on Ubuntu, Fedora, and Red Hat.

  • To install the package on Ubuntu, enter:

    sudo apt-get install patch
  • To install the package on Fedora, lsign in as root and enter:

    dnf install patch
  • To install the package on Red Hat, lsign in as root and enter:

    yum install patch -`uname -r`

eMake options for Android builds

Using eMake for Android builds requires two eMake options, which you use to specify your Android version and your Android source file location. eMake uses these options to automatically configure the build for best performance and compatibility with Android:

--emake-android-version=<version>

where `<version>` is 7.0.0, 8.0.0, 9.0.0, 10.0.0, or 11.0.0

and

--emake-android-root=<path>

where `<path>` is the directory path to your source files.

What eMake options does --emake-android-version set automatically?

The --emake-android-version option sets many build-related command-line options such as parse avoidance and whether to ignore directory read conflicts (readdir-conflicts). eMake sets --emake-readdir-conflicts=1 in a learning build to ensure a comprehensive history. In non-learning builds, it is set to 0 for the best performance.

Following is the full list of options that it automatically sets:

--emake-assetdir=<variable> --emake-history=<variable> --emake-historyfile=<variable> --emake-root=<variable> --emake-readdir-conflicts=<variable> --emake-blind-create=1 --emake-parse-avoidance=1 --emake-suppress-include=*.d --emake-suppress-include=*.P --emake-optimize-schedule=1 --emake-optimize-deps=1 --emake-jobcache=all --emake-pragmafile=<EA_CONF>/emake.pragmas --emake-parse-avoidance-ignore-env=EMAKE_DEBUG --emake-parse-avoidance-ignore-env=EMAKEFLAGS --emake-parse-avoidance-ignore-env=EMAKE_LICENSE_FILE --emake-parse-avoidance-ignore-env=WRAPPER_BITS --emake-parse-avoidance-ignore-env=WRAPPER_PID --emake-parse-avoidance-ignore-env=XDG_SESSION_COOKIE --emake-parse-avoidance-ignore-env=TMPDIR --emake-parse-avoidance-ignore-env=TERM --emake-parse-avoidance-ignore-env=EMAKE_READDIR_CONFLICTS --emake-parse-avoidance-ignore-env=COMMANDER_WORKSPACE_WINDRIVE --emake-parse-avoidance-ignore-env=COMMANDER_WORKSPACE_NAME --emake-parse-avoidance-ignore-env=COMMANDER_WORKSPACE_UNIX --emake-parse-avoidance-ignore-env=COMMANDER_WORKSPACE_WINUNC --emake-parse-avoidance-ignore-env=COMMANDER_SESSIONID --emake-parse-avoidance-ignore-env=COMMANDER_JOBSTEPID --emake-parse-avoidance-ignore-env=COMMANDER_JOBID --emake-parse-avoidance-ignore-env=PROMPT_COMMAND --emake-autodepend=1

Except for the --emake-historyfile option, if you must specify other values for any of these options, you must place those options in the eMake command after the --emake-android-version option so that they are not overridden.

How eMake detects and kickstarts Android learning builds

eMake tries to determine if you lack a history file (if so, the build is a “learning” build). In this case, eMake creates a “kickstart” history file for your Android version to help reduce the build duration.

eMake uses the name that you set for your history file. It also sets --emake-history=create so that the new history from your learning build omits the kickstart history.

Using --emake-android-root for builds that do not start in the Android source root

A build might start with a top-level makefile other than the one belonging to Android. For example, if a makefile contains the following line:

# do some other stuff#....... now_build_android: cd $(ANDROID_ROOT) && $(MAKE)

Then eMake would be unable to find the original files in the current directory of the top-level Make. To avoid this issue, you should always use the --emake-android-root eMake option to set the path to the Android source files.

Sample eMake command for an Android build

Following is an example eMake invocation that uses both Android-specific options:

emake --emake-android-version=10.0.0 --emake-android-root=../AndroidP -f MyTopLevelMakefile.mk

Supported Android versions

This section applies to Android 7. x (“N”), 8. x (“O”), 9. x (“P”), 10. x (“Q”), and 11. x (“R”).

See also