AOSP pre install App
Target
Pre install android app into android ROM
Prepare AOSP build environment
Follow steps of AOSP setup.
Our sample environment:
branch: master (repo init -u https://android.googlesource.com/platform/manifest)
target: aosp_x86-eng
device: emulator
Init env every time open a new terminal:
Build an APK for pre-install
Use Android Studio to build an apk. I built a TestMan.apk.
Place apk to aosp pre-install apps
-
Make a dir TestMan in AOSP_WORKSPACE/packages/apps.
-
Put TestMan.apk here.
-
Make an Android.mk in AOSP_WORKSPACE/packages/apps/TestMan.
Android.mk:
Each line should not have trailing spaces, or you would get error Invalid characters in module stem \(LOCAL_INSTALLED_MODULE_STEM\)
when you build.
Modify makefile
Open AOSP_WORKSPACE/build/target/product/aosp_x86.mk.
aosp_x86.mk:
We can see there is $(SRC_TARGET_DIR)/product/gsi_common.mk which every {TARGET} .mk files call.
Then we need to add TestMan to Default AOSP packages in makefile.
Open AOSP_WORKSPACE/build/target/product/gsi_common.mk
We can see
Add TestMan here
Add TestMan to whitelist in gsi_common.mk.
Build
-
Go to AOSP_WORKSPACE, run
make -j8
ormake -j16
… (depend on your CPU cores) -
If you got
#### build completed successfully (02:17 (mm:ss)) ####
, runemulator
, you can see TestMan is already an in pre-install app which cannot be uninstall.
How to replace default launcher with customized launcher
Find default launcher of AOSP
Launcher is also a pre-install app, so we can find it under AOSP_WORKSPACE/packages/apps/.
We can see there are Luncher2 and Luncher3, why there are two launchers?
We can check their Android.mk to see what’s going on. Launcher2 does not have Android.mk, but Launcher3 has.
We can see there is LOCAL_OVERRIDES_PACKAGES := Home Launcher2 Launcher3 Launcher3QuickStep
. Check what is LOCAL_OVERRIDES_PACKAGES.
From How do I add APKs in an AOSP build? we know that Launcher3 module hide Home Launcher2 Launcher3 Launcher3QuickStep
.
So why does Launcher3 hide itself? Check Android.mk again we can also see LOCAL_PACKAGE_NAME := Launcher3QuickStepGo
.
From Android.mk we see:
LOCAL_PACKAGE_NAME is the name of an app. For example, Dialer, Contacts, etc.
LOCAL_MODULE is the name of what’s supposed to be generated from your Android.mk. For exmample, for libkjs, the LOCAL_MODULE is “libkjs” (the build system adds the appropriate suffix – .so .dylib .dll). For app modules, use LOCAL_PACKAGE_NAME instead of LOCAL_MODULE.
So we should always use LOCAL_PACKAGE_NAME when pre-install module is an App and build with source code. But if we use apk instead of source code, we should always use LOCAL_MODULE, otherwise you’ll get error when build.
Finally, we can see Launcher3’s real name is Launcher3QuickStepGo, and there are other LOCAL_PACKAGE_NAME in Android.mk of Launcher3: Launcher3, Launcher3Go, Launcher3QuickStep. We should use LOCAL_OVERRIDES_PACKAGES := Home Launcher2 Launcher3 Launcher3QuickStep Launcher3QuickStepGo
in our own launcher app’s Android.mk to hide them all.
Build new launcher apk to replace default launcher
Then we need to build a launcher apk and place it to AOSP_WORKSPACE/packages/apps/ with the same way of pre-install common apk metioned above. Modify gsi_common.mk, add it to product_packages and whitelist.
Android.mk of NewLauncher:
Build
-
Run
make installclean
to remove default launcher apk which generated under AOSP_WORKSPACE/out directory. -
Run
make -j8
-
Run
emulator
to see new launcher after boot.
(If you do not hide default launcher with LOCAL_OVERRIDES_PACKAGES, you will need to select a launcher after boot.)
Clean
If you remove pre install app, you need to run make installclean
before make
.
If you want to clear app data, you need to run make dataclean
before make
.
References
How do I add APKs in an AOSP build?