B02b: Explore Build Commands and Tooling

B02b: Explore Build Commands and Tooling

Build an Image for our Target Device

If you are using a build environment already prepared by the trainers (VM, external SSD drive), the following command will unexpectedly complete very quickly. We have done the heavy lifting for you already 🙂.

# After 'source/envsetup.sh' and 'lunch'!
m -j$(nproc)

Note

On many POSIX-compatible systems, the nproc command prints the number of currently online processors. In case you are using one of our provided cloud instances, the nproc command will return 24, since the virtual machines have 24 cores. E.g., you can also just use

m -j24

Explore Build Commands, Options and Tooling

Useful commands for building parts of Android include:

# Trigger a full build for a target, starting at the top of the tree:
m
make     # make only works from the top of tree!

# Build and install all modules from the current directory as well as their dependencies:
mm
mma

# Build and install all of the modules in the supplied directories as well as their dependencies:
mmm dir1, dir2, ..
mmma dir1, dir2, ..

The m command also offers ways to clean up an already existing out directory. Make sure to read the following commands and understand their consequences, before entering them on your development machine:

# Clean the out/target/product/<productname>/*.img files.
m installclean
# Important:
#   After 'm installclean', the cuttlefish virtual device will not work anymore,
#   because its bootable image has just been deleted. You will need to re-generate
#   the deleted files by using 'm'.

# Clean build artifacts
# DO NOT EXECUTE THESE NOW, a clean build needs several hours to complete!
# m clean
# m clobber

More detailed help output and an explanation of the different command line tools and arguments can be obtained as follows:

# Help for tools and commands like lunch, mm, Android-specific grep tools, etc.:
hmm

# Help for build targets like clean, sync, snod:
m help

A selection of tools you might find useful:

# Go back to top of tree
croot

# Specific grep variants
cgrep        # C/C++
ggrep        # Gradle
gogrep       # Go
jgrep        # Java
jsongrep     # JSON
ktgrep       # Kotlin
mangrep      # AndroidManifest.xml
mgrep        # Makefiles and *.bp
owngrep      # OWNERS
rsgrep       # Rust
sepgrep      # sepolicy
sgrep        # Source files
tomlgrep     # TOML
pygrep       # Python

# more?

Build a Software Bill of Materials (SBoM) and Explore the out Directory

m sbom

# Output
ls out/<dist>/sbom*

# If you've used the aosp_cf_x86_64 target from above, replace <dist> accordingly:
ls out/soong/sbom/aosp_cf_x86_64_auto/sbom*