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

孤者浪人 提交于 2020-12-04 05:25:34

问题


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 ?


回答1:


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




回答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




回答3:


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)




回答4:


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?



来源:https://stackoverflow.com/questions/60487784/how-to-add-pre-built-app-system-app-in-aosp-source-code

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!