How to Add Pre-built App (System App) in AOSP source code
Asked Answered
B

4

9

I was trying to add an APK in AOSP version 10 as system application. I have followed the procedure mentioned in almost different links which is here Add apk in AOSP but nothing worked. The process mentioned in this link and the steps I followed are:

  1. Put my Apk in Aosp_root/packages/apps/my-app-folder/my-app.apk
  2. Write Android.mk of my-app.apk in /my-app-folder

Code of Android.mk

    LOCAL_PATH := $(call my-dir)
    
    include $(CLEAR_VARS)
    
    LOCAL_MODULE_TAGS := optional
    
    LOCAL_MODULE := Signal
    
    LOCAL_CERTIFICATE := platform
    
    LOCAL_SRC_FILES := Signal-website-universal-release-4.55.8.apk
    
    LOCAL_MODULE_CLASS := APPS
    
    LOCAL_MODULE_SUFFIX := $(COMMON_ANDROID_PACKAGE_SUFFIX)
    
    include $(BUILD_PREBUILT)
  1. Then in step 3 to add PRODUCT_PACKAGES in core.mk or common.mk I could not find both specified files (core.mk or common.mk) in specified directory (build/target/products). But I found gsi-common.mk file in build/target/product folder and found PRODUCT_PACKAGES in this file and added directory of my-app in it.

here is code of gsi-common.mk.

   `PRODUCT_PACKAGES += \
    messaging \
    PhotoTable \
    WAPPushManager \
    WallpaperPicker \
    Signal \`
  1. After rebuilding AOSP for aosp-root and flashing it on device nothing has changed, my-app.apk was not added. Then i used mm command in packages/apps directory and it built my-app.apk and it was added in aosp_root/out/target/product/taimen/system/app. After it I run make snod command to re-generate system image and it was created. When I flashed this image in my Pixel device it stucks on Google logo and also shows operating system is corrupt before it shows google logo.

Can you tell me what I am missing or which step is wrong ?

Brake answered 2/3, 2020 at 11:19 Comment(10)
Welcome to Stack Overflow - have a look at this article stackoverflow.com/help/how-to-ask It'll help you to improve your question, which will mean you have a better chance of finding the answer you are looking for.Intercrop
@Brake Hi did you fix it? I'm facing the same problem. The apk is added in the system but it's not appearing in the ROMConfect
@ShivamJha No, Its not fixed yet, I am working on it. I will let you know when done and If you did before me then you tell meBrake
Hi I am having a similar problem. I can see that my apk was added to the /system/app/FOLDER dir, however I cannot see its launch icon. Any idea on what may be happening?Squalid
@caiomcg: How you added app ? Did you followed same process which I followed ? and if app is added in your system.img and your are not seeing its launch icon after flashing system.img in device then it might be some issue with your app. or read right permissions issueBrake
Hi @Brake thank you for the quick response. I did a fairly similar process, my makefile is a little different, I needed to disable ART optimization as my target is not the api version of this device even tough it is in the ranges between compileSdkVersion and minSdkVersion. My APK is presigned and has been tested before as regular app on the same device. I can see the apk in the system/app folder of the device through ADB but it is not installed. I can try installing with a test app just to make sure. Can you elaborate on the read right permission issues. Thanks in advanceSqualid
@caiomcg: If it is added it should be installed as well. read write permission means that your .apk should have similar permissions as your source code. Your build should have complete access to .apk. You can check permissions by ls-l commandBrake
@Brake I have 664 permission on the apk. I listed every occurence of my app on the out folder and I can see the apk under system/app and a folder containgni package.apk and package.apk.unaligned under /obj/APPS/MyApp_intermediates. Any other suggestion?Squalid
@Squalid Then try adding a different app. If same thing happens with it then issue is with your modifications and if that app works it means issue is with your app. You can create a simple app with only one or two buttons in android studio.Brake
@Brake Yep, doing it right now. Thank you for the help so far :)Squalid
W
10

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

Winterize answered 20/11, 2020 at 7:0 Comment(2)
Do you know how to add .so libraries of app in makefile or aosp ? I am having library issue in an apk. It works fine as user app but library issue as system appBrake
I have solved it, my issue was I was writing module name in wrong file in build/target/product/. After writing it in handheld_system.mk solved the issueBrake
D
2

Adding a pre-built app to the build

In the AOSP root add the folder:

/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 (usually 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 will find the new app installed on the system.

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

If you wish to install the APK in /system/priv-app, you will need to add the following line to Android.mk

LOCAL_PRIVILEGED_MODULE := true

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)

Reference : How do I add APKs in an AOSP build?

Davies answered 2/3, 2020 at 12:25 Comment(2)
Please add your changes to the question which you have tried so far and found not working.Davies
I have edited the question and listed the whole process which I followed. Please review it nowBrake
C
2

Additional steps needed in AOSP10:

First, add your module name to PRODUCT_PACKAGES in:

<aospbase>\build\make\target\product\base_system.mk

This adds the APK to the system

Second, whitelist permissions (if needed, otherwise device fails to boot): After make, run development/tools/privapp_permissions/privapp_permissions.py

If the resulting set of permissions isn't empty, add the output to: frameworks/base/data/etc/privapp-permissions-platform.xml

Reference: https://source.android.com/devices/tech/config/perms-whitelist

Credence answered 17/5, 2020 at 14:30 Comment(1)
Hi @Hermet, Do you know how to add system app in aosp from app source code (Complete android studio project). I have tried several ways but its not working. Here is link of my errorBrake
Z
0

Before you build Android image from AOSP you must to choose the build target by "lunch" command. In case you build for Google Pixel device which use processor Qualcomm Snapdragon 8xx you should lunch as like below:

$ lunch aosp_arm64-eng

In this case the output image should contain the packages included in build/target/products/gsi_common.mk

For sure, you should try

$ make installclean
$ make -j32 #may be -j16, -j8, etc. depends on your build host

then check again for your application in output image.

If system is still corrupt, could you provide more related information (ex: logcat)

Zerlina answered 4/3, 2020 at 7:48 Comment(3)
I have added apk and build code from cleanproject but its still not added in systemBrake
@semw: did you check the directory /system/app and /system/priv-appZerlina
yes i have checked both folders, app is not added.Brake

© 2022 - 2024 — McMap. All rights reserved.