Intro

Sometimes we need to add some pre-built apk in our build because the source isn’t available or it is more easy to just pull the binaries from, and add it to our build. This post says how to do it.

Implementation

Suppose that we have our vendor as CUSTOM_VENDOR

  1. In vendor/CUSTOM_VENDOR/prebuilt/app, create a folder named MyCoolApp.

  2. In MyCoolApp folder, add the apk MyCoolApp.apk and a Android.mk

vendor/
├──CUSTOM_VENDOR/
├──config/
│ └── common.mk
└── prebuilt
    └── app/
        MyCoolApp/
        ├── MyCoolApp.apk <--
        └── Android.mk <--
  1. Android.mk file which contains the following instructions

Android.mk

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

LOCAL_MODULE_TAGS := optional
LOCAL_MODULE := Testapk
LOCAL_SRC_FILES := $(LOCAL_MODULE).apk
LOCAL_MODULE_CLASS := APPS
LOCAL_CERTIFICATE := PRESIGNED

# LOCAL_PRIVILEGED_MODULE = true
# LOCAL_MODULE_PATH := $(TARGET_OUT_DATA)
# LOCAL_OVERRIDES_PACKAGES := Home Launcher2  Launcher3

LOCAL_MODULE_SUFFIX :=  $(COMMON_ANDROID_PACKAGE_SUFFIX)

include $(BUILD_PREBUILT)
  1. That’s it ! Add following instruction with respected device/vendor.
PRODUCT_PACKAGES +=\
    MyCoolApp

Notes:

  1. If your APK is already not signed, use the u wat to use for signing as value for LOCAL_CERTIFICATE

    LOCAL_CERTIFICATE can have following values

    • PLATFORM or
    • PRESIGNED or
    • <KEY>
  2. If you want it as system app use LOCAL_PRIVILEGED_MODULE = true

  3. If you want your APK to end up in the /data/app/ directory, add the line

    LOCAL_MODULE_PATH := $(TARGET_OUT_DATA)
    
  4. If you want to Override some packages, use

    LOCAL_OVERRIDES_PACKAGES := Home Launcher3 <package name>
    

References