Generate vendor snapshots

Android 11 supports VNDK snapshot build artifacts and vendor snapshots, which you can use to build vendor.img regardless of the Android version on the source tree. This enables mixed versions of images, such as an older vendor and a newer system image.

Mixed image versions aren't supported for the following.

  • Android.mk. Because Soong generates the vendor snapshot, modules defined in Android.mk aren't captured as a vendor snapshot (SoC-proprietary modules in Android.mk also aren't guaranteed to work).

  • Sanitizer. Vendor and VNDK snapshots don't support sanitizer as sanitizer variants need to be built separately.

About vendor snapshots

A vendor snapshot is an OEM-owned snapshot. It's a set of prebuilt C++ modules installed in /vendor but maintained on AOSP. Without capturing a vendor snapshot of the previous Android version, upgrading to a new Android version might break the vendor partition because vendor snapshot modules can be removed or changed without API or ABI compatibility.

A vendor snapshot contains following modules on AOSP.

  • Shared, static, and header libraries with vendor: true or vendor_available: true
  • VNDK static libraries with vendor_available: true
  • Executables and object files with vendor: true or vendor_available: true

Modules under the following directories are considered SoC-owned hardware code and are ignored.

  • device/
  • vendor/
  • hardware/, except for
    • hardware/interfaces
    • hardware/libhardware
    • hardware/libhardware_legacy

SoC-owned hardware codes might also exist in other directories. At this time, vendor snapshots don't support such configurations.

Build vendor snapshots

Build a vendor snapshot using the following commands.

. build/envsetup.sh
lunch target
m dist vendor-snapshot

These commands create a vendor-$(TARGET_DEVICE).zip file in $DIST_DIR. The following example shows a vendor snapshot zip file:

vendor-$(TARGET_DEVICE).zip
├── arch-arm64-armv8-a
│   ├── binary         -> binary files, *.json files
│   ├── header         -> *.json files
│   ├── object         -> *.o files, *.json files
│   ├── shared         -> *.so files, *.json files
│   └── static         -> *.a files, *.json files
├── arch-arm-armv8-a   -> (arch-arm64-armv8-a)
├── configs            -> *.rc files, *.xml files
├── include            -> exported header files (*.h, *.hh, etc.)
└── NOTICE_FILES       -> license txt files
  • The JSON files contain flags such as module name, exported directories, init_rc files, and vintf_fragments files.
  • The configs directory contains .rc and .xml files from flags init_rc and vintf_fragments.

Install vendor snapshots

To install a vendor snapshot, navigate to the destination directory and use the following commands.

python3 development/vendor_snapshot/update.py --local $DIST_DIR --install-dir \
    vendor/vendor name/vendor_snapshot VER

This command generates /vendor/vendor name/vendor_snapshot/vVER/$(TARGET_ARCH)/Android.bp. The following example shows the directory structure of a vendor snapshot:

vendor/vendor name/vendor_snapshot/
├── v30
│   ├── arm64
│   │   ├── arch-arm64-armv8-a
│   │   │   ├── binary         -> (prebuilt libs)
│   │   │   ├── object         -> (prebuilt libs)
│   │   │   ├── shared         -> (prebuilt libs)
│   │   │   └── static         -> (prebuilt libs)
│   │   ├── arch-arm-armv8-a   -> (same as above)
│   │   ├── configs            -> (config files)
│   │   ├── include            -> (exported header files)
│   │   ├── NOTICE_FILES       -> (license files)
│   │   └── Android.bp         -> (snapshot modules)
│   ├── arm                    -> (same as above)
│   ├── x86_64                 -> (same as above)
│   └── x86                    -> (same as above)
└── (other vendor versions)    -> (same as above)

Build vendor images

Using VNDK snapshot build artifacts and a vendor snapshot, you can build vendor.img regardless of the Android version on the source tree, making it possible to create mixed versions of images. After installing both the VNDK snapshot and vendor snapshot, set BOARD_VNDK_VERSION to the vendor's version. For example:

# BoardConfig.mk
BOARD_VNDK_VERSION := 29

When BOARD_VNDK_VERSION is set to a value other than current, the build system:

  • Enables VNDK snapshot modules and vendor snapshot modules of BOARD_VNDK_VERSION. Each snapshot module overrides a C++ source module having the same name.
  • Sets ro.vndk.version to BOARD_VNDK_VERSION.
  • Installs VNDK snapshot modules of BOARD_VNDK_VERSION to system_ext.