47

I need to add some 3rd party APKs to my AOSP build. What folder should I keep these APKs so that when I build the code and the image is created, it is installed in the emulator?

It looks like the system apps are kept in the packages/app folder so I need to know where the third party APKs are kept.

Daniel
  • 2,355
  • 9
  • 23
  • 30
CodeGuru
  • 726
  • 1
  • 6
  • 13
  • Possible duplicate of [Add prebuilt APKs to Android AOSP system.img](http://stackoverflow.com/questions/8387477/add-prebuilt-apks-to-android-aosp-system-img) – Cameron Martin Jul 01 '16 at 10:03

4 Answers4

68

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 for LOCAL_CERTIFICATE
  • If you want your APK to end up in the /data/app/ directory, add the line LOCAL_MODULE_PATH := $(TARGET_OUT_DATA) before the line include $(BUILD_PREBUILT)
Alex Mazzariol
  • 2,456
  • 1
  • 19
  • 21
Tiago Costa
  • 971
  • 8
  • 10
  • 7
    Thank you. I was growing tired of all the ROM kitchen posts I see. – Silas Greenback Dec 12 '13 at 17:37
  • 1
    @Tiago: what will be LOCAL_CERTIFICATE := < desired key >. could you please clear this. – Raj Apr 09 '15 at 07:39
  • Sorry for the delay, also sorry for the mess here, but the reply formatting is not working. The core Android platform uses four keys to maintain security of core platform components: 1. platform: a key for packages that are part of the core platform. 2. shared: a key for things that are shared in the home/contacts process. 3. media: a key for packages that are part of the media/download system. 4. releasekey: the default key to sign with if not otherwise specified. See here: http://www.kandroid.org/online-pdk/guide/release_keys.html – Tiago Costa May 12 '15 at 09:11
  • 1
    @TiagoCosta Do you know what you have to add to do the same thing for a system privileged app? That is one that should be in system/priv-app? I've posted a question http://stackoverflow.com/questions/32997233/adding-system-apk-to-android-custom-rom – Adam W Oct 07 '15 at 20:27
  • Is is possible to install multiple apk in given dir this way? Not knowing the apk names. Lets say we change apks in the dir often, and we want to copy all of them to out dir. – pera Apr 18 '16 at 14:08
  • Does the LOCAL_CERTIFICATE mean the APK should be unsigned? – Bobbake4 Apr 19 '16 at 19:28
  • @TiagoCosta And what should I do to add root permission to that APK? – Dr.jacky May 15 '16 at 07:13
  • 2
    @Raj apparently you can also use the `presigned` value: https://groups.google.com/forum/#!topic/android-building/i4oaJ2DtadM – Cameron Martin Jul 01 '16 at 09:48
  • what determines the path to the APK when built? – Innovine Aug 23 '17 at 09:34
  • 1
    AOSP 8.1.0 - There is no common.mk file, do I manually create this? – HyperionX Apr 13 '18 at 00:09
  • 2
    @HyperionX use core.mk – Methnani Bilel Jun 06 '18 at 02:34
  • ninja: error: 'packages/apps/DoorUnit/doorunit', needed by 'out/target/product/pico_imx8mm/obj/APPS/DoorUnit_intermediates/package.apk', missing and no known rule to make it – Pawan Soni Jan 27 '21 at 11:54
9

The Android.mk presented above will install the APK in /system/app

If you wish to install the APK in /data/app you will need to add the following the line to Android.mk before line include $(BUILD_PREBUILT)

LOCAL_MODULE_PATH := $(TARGET_OUT_DATA)
bjb568
  • 11,089
  • 11
  • 50
  • 71
user3913384
  • 119
  • 1
  • 2
5

You could also do the following in the target output dir:

<path-to-your-build-dir>/host/linux-x86/bin/simg2img system.img temp.img
mkdir system_root
sudo mount -t ext4 -o loop temp.img system_root

At this point you can make whatever changes you'd like to the files in system_root, i.e. adding apks to system/app etc...

When you're done just go back down to the output dir and do:

sudo umount system_root
<path-to-your-build-dir>/host/linux-x86/bin/img2simg temp.img system.img

You can now flash system.img using fastboot as usual.

Justin Buser
  • 2,813
  • 25
  • 32
  • 3
    That's a lot closer, but not quite an answer to the specific question asked as this method is a post-build modification to the image rather than a way to have the build process include the apps. Still, it could at least be scripted. – Chris Stratton Jan 26 '13 at 17:46
1

Follow the first answer to make the apk and Android.mk file and place it where it is supposed to. But now there is no core.mk file in build/target/product but it has been renamed to handheld_product.mk So, add your app's folder name there.

SHR
  • 7,940
  • 9
  • 38
  • 57
Anmol Agrawal
  • 11
  • 1
  • 4