Embedding precompiled .APK into Android ROM

There a lot of tutorials out there on how to build your own Android ROM from sources and how to integrate your application into the build process. However, there are very few clean instructions on how to put your own precompiled .apk into the ROM. Here is how (I assume you have an Android working tree ready):

  1. Create a folder for your app: packages/apps/<your-app-name>
  2. Put your .apk into the packages/apps/<your-app-name>/<your-app-name>.apk
  3. Create the Android.mk file just next to it. Is should contain:
LOCAL_PATH := $(call my-dir)include $(CLEAR_VARS)
LOCAL_MODULE_TAGS := optional
LOCAL_MODULE := <your-app-name>;
LOCAL_CERTIFICATE := PRESIGNED
LOCAL_SRC_FILES := $(LOCAL_MODULE).apk
LOCAL_MODULE_CLASS := APPS
LOCAL_MODULE_SUFFIX := $(COMMON_ANDROID_PACKAGE_SUFFIX)
include $(BUILD_PREBUILT)

Now Android build system will recognize the package with your application. To include it into the ROM add <your-app-name> to the PRODUCT_PACKAGES variable for a desired target configuration. I.e. in build/target/product/full_base.mk.

Build the ROM as usual and you will have your precompiled application embedded into it.

If you have native C++ library inside your .apk, you should unpack it manually, put into the packages/apps/<your-app-name> folder and describe it in Android.mk:

include $(CLEAR_VARS)
LOCAL_IS_HOST_MODULE:=
LOCAL_MODULE_CLASS:=SHARED_LIBRARIES
LOCAL_MODULE_TAGS:=optional
OVERRIDE_BUILT_MODULE_PATH:=$(PRODUCT_OUT)/obj/lib
LOCAL_UNINSTALLABLE_MODULE:=
LOCAL_SRC_FILES:=<your-library.so>
LOCAL_BUILT_MODULE_STEM:=<your-library.so>
LOCAL_STRIP_MODULE:=
LOCAL_MODULE:=<your-library>
LOCAL_MODULE_STEM:=<your-library.so>
LOCAL_CERTIFICATE:=
LOCAL_MODULE_PATH:=$(PRODUCT_OUT)/system/lib
LOCAL_REQUIRED_MODULES:=
LOCAL_SHARED_LIBRARIES:=
include $(BUILD_PREBUILT)

Add it as a dependency to your prebuilt .apk package:

LOCAL_REQUIRED_MODULES := <your-library>

The library will be copied to the system/lib folder of the target ROM.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.