How do I add APKs in an AOSP build?
Adding third party APKs to the build is definitely possible.
Also APKs and APPs with source code go to the same place; the package/app
folder.
Adding a new APK to the build
In the AOSP root add the folder:
<aosp root>/package/app/< yourappfolder >
Then inside this folder add:
- empty
Android.mk
< yourapp.apk >
The android make file should have the reference to your apk, add this to your Android.mk
:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE_TAGS := optional
LOCAL_MODULE := < your app folder name >
LOCAL_CERTIFICATE := < desired key >
LOCAL_SRC_FILES := < app apk filename >
LOCAL_MODULE_CLASS := APPS
LOCAL_MODULE_SUFFIX := $(COMMON_ANDROID_PACKAGE_SUFFIX)
include $(BUILD_PREBUILT)
Create an entry in the commons.mk
(from AOSP 8.1.0 onwards it is called core.mk
, and is usually found in build/target/product
) for your apk add the line (check where all the others are)
PRODUCT_PACKAGES += < what you have defined in LOCAL_MODULE, it should be your app folder name >
Compile the AOSP and you have a brand new app installed on the system.
Notes
- If your APK is already signed, use the special value
PRESIGNED
as value forLOCAL_CERTIFICATE
- If you want your APK to end up in the
/data/app/
directory, add the lineLOCAL_MODULE_PATH := $(TARGET_OUT_DATA)
before the lineinclude $(BUILD_PREBUILT)
Is it possible to add a prebuilt APK to an AOSP build as an user app?
I found the standard behavior of the PackageManager class good enough for my use case. So here are a couple tidbits worth explaining:
- Lavakush's answer does work and it does output the APK to the out/target/product/vendor/data/app folder in the source tree but the APK does not show up under /data/app in the system image once it's flashed onto a device. According to this answer, the Android build system does not build anything into /data/ so that explains that. I still find it confusing that it does show up as output in the out/target/product/vendor/data/app folder however.
- In my use case, I need to preload APKs onto a build and then update them as needed. Due to the read-only nature of the /system/app folder I assumed that I would not be able to update my app which is why I wanted to preload it to /data/app. As in turns out, according to this answer & to my testing, the PackageInstaller class' standard behavior is to install the updated APK to the data/app folder and to start running this APK instead of the preloaded /system/app APK. The answer also says that the settings->apps screen will give you the option to uninstall the updated APK and then you'll be left with the original system/app APK. I did observe this behavior and it is fine for my use case.
How to Add Pre-built App (System App) in AOSP source code
Answering this for Android 11 and Android 8.1
Create a folder for your application in<AOSP-root-directory>/package/apps/<yourAppFolder>
Inside yourAppFolder
create an Android.mk
file with below content
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE_TAGS := optional
LOCAL_MODULE := < your app folder name >
LOCAL_CERTIFICATE := platform
LOCAL_SRC_FILES := < app apk filename >
LOCAL_MODULE_CLASS := APPS
LOCAL_MODULE_SUFFIX := $(COMMON_ANDROID_PACKAGE_SUFFIX)
include $(BUILD_PREBUILT)
Put your apk file in the same folder.
Now we've to include the apk in the system image to do that, to do that we've to mention the module name in the PRODUCT_PACKAGES
list in the file:
For android 11 -aosp-root-dir/build/target/product/handheld_system.mk
For android 8.1 -aosp-root-dir/build/target/product/core.mk
Add prebuilt apk to AOSP build
The problem with my Android.mk
file was that it had trailing spaces on each line. Everything worked fine after I deleted these trailing spaces.
Integrate an apk into AOSP's build system and run it on boot
The app that starts first and shows your Home screen, App drawer etc. is called a Launcher.
You can either:
- Have your new app be a Launcher app. You'll need to modify it to add the HOME intent, and also set it as the default launcher of the system.
- Or modify your current Launcher app to open your app as soon as it itself starts.
How to add pre-built System App in Android 12 AOSP
After some research, I found that PRODUCT_PACKAGES should be declared here/AOSP/packages/services/Car/car_product/build/car.mk
Related Topics
How to Get Hosting Activity from a View
Android - Hold Button to Repeat Action
Flutter Projects & Android X Migration Issues
Android: How to Check If the Server Is Available
How to Set Up Dagger Dependency Injection from Scratch in Android Project
Cannot Resolve Symbol 'Appcompatactivity'
Modifying Camera Output Using Surfacetexture and Opengl
Is Using Serializable in Android Bad
Navigation Drawer: Set as Always Opened on Tablets
Toolbar Overlapping Below Status Bar
Error :: Duplicate Files During Packaging of APK
Detect Touch Event on a View When Dragged Over from Other View
How to Make Android Apps Which Support Both 32-Bit and 64-Bit Architecture
Actionbaractivity Cannot Resolve a Symbol