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:
Put my Apk in Aosp_root/packages/apps/my-app-folder/my-app.apk
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)
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 \`
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 ?
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
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
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?
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)
Related
I have been trying to add a apk to priv-app.
Following are the steps i did:
Made a folder named Testapk in packages/apps
Copied apk to folder with name Testapk.apk
In same directory, created an Android.mk file with following contents:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE_TAGS := optional
LOCAL_MODULE := Testapk
LOCAL_CERTIFICATE := PRESIGNED
LOCAL_SRC_FILES := Testapk.apk
LOCAL_MODULE_CLASS := APPS
LOCAL_MODULE_SUFFIX := $(COMMON_ANDROID_PACKAGE_SUFFIX)
LOCAL_PRIVILEGED_MODULE := true
TARGET_OUT_DATA_APPS_PRIVILEGED := $(TARGET_OUT_DATA)/priv-app
include $(BUILD_PREBUILT)
Then, added Testapk to /build/target/product/base_system.mk
Build is successful and i can see my apk in priv-app folder in out/target/product/sdm660_64/system/priv-app. After flashing, the device wont boot up. Its stuck on Android logo.
I am using Qualcom SDM660, the branch is android-10
If I add the apk to system/apps, i can boot and the apk works fine.
Can someone help me on this???
You haven't shared the Crash Stack here. Its difficult to tell.
I could see here that
Are you requesting any privileged permissions from the app side ? if yes, device will not boot until you whitelist those permissions in privileged permissions xml file which will be stored at either system/etc/permissions
I've made a couple attempts to add a single shared object library to an Android 10 build by adapting older instructions here and here.
I added a directory containing the library under /device/vendor/name/ and an Android.mk file using the two-target example.
They have all lead back to the same error:
build/make/core/base_rules.mk:480: error: writing to readonly directory: "system/lib64/libjni_latinimegoogle.so"
Is there a correct/accepted way to do this for 10? Thanks
edit: Android.mk file contents
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := libjni_latinimegoogle
LOCAL_MODULE_SUFFIX := .so
LOCAL_MODULE_CLASS := SHARED_LIBRARIES
LOCAL_MODULE_TAGS := optional
LOCAL_PRELINK_MODULE := false
ifdef TARGET_2ND_ARCH
LOCAL_MULTILIB := both
LOCAL_MODULE_PATH_64 := system/lib64
LOCAL_SRC_FILES_64 := system/lib64/libjni_latinimegoogle.so
LOCAL_MODULE_PATH_32 := system/lib
LOCAL_SRC_FILES_32 := system/lib/libjni_latinimegoogle.so
else
LOCAL_MODULE_PATH := system/lib64
LOCAL_SRC_FILES := system/lib64/libjni_latinimegoogle.so
endif
include $(BUILD_PREBUILT)
The problem is with using kati.
This occurs when you try to generate build output outside of out/. Or, in the case of the kernel, if you use absolute paths for the build target. The kernel part is not in your focus, but someone might need this information.
Therefore, your LOCAL_MODULE_PATH is pointing to invalid location.
The correct way is to specify in the device makefile. The goal was to add gesture typing to a LineageOS 17.1 build - using the Pixel 3XL crosshatch as an example:
in vendor/google/crosshatch/crosshatch-vendor.mk under PRODUCT_COPY_FILES, add the row to copy the .so library similar to the ones around it, under lib64 (or lib for 32 bit device builds):
PRODUCT_COPY_FILES += \
...
vendor/google/crosshatch/proprietary/lib64/libjni_latinimegoogle.so:$(TARGET_COPY_OUT_SYSTEM)/lib64/libjni_latinimegoogle.so \
...
TARGET_COPY_OUT_SYSTEM will direct it to the system partition vs PRODUCT, SYSTEM_EXT, or VENDOR which are also options.
Finally make sure to add the .so file where it needs to be copied from locally, under vendor/google/crosshatch/proprietary/lib64
Gesture typing will be enabled in the next build. This is also working with LineageOS 18.1
I am looking to add a prebuilt APK to AOSP build using the emulator. I successfully installed an APK into system/app directory by doing the related questions.
But I want to add an APK into data/app directory.
My development environments are followings:
- Ubuntu 16.04 LTS
- AOSP: android 6.0.1_r77
- AOSP emulator
I tried the following steps by the several related questions.
Add the APK to the /packages/apps directory.
Create an Android.mk file.
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE_TAGS := optional
LOCAL_MODULE := <name of APK>
LOCAL_SRC_FILES := <Name of APK>.apk
LOCAL_MODULE_CLASS := APPS
LOCAL_MODULE_SUFFIX := $(COMMON_ANDROID_PACKAGE_SUFFIX)
LOCAL_CERTIFICATE := platform
LOCAL_MODULE_PATH := $(TARGET_OUT_DATA)
include $(BUILD_PREBUILT)
Add in /build/target/product/core.mk
PRODUCT_PACKAGES += \ <name of APK>
The above Android.mk file didn't even install the APK into system/app.
And I also tried the followings. The following make files installed the APK into system/app.
...
LOCAL_MODULE_TAGS := tests
...
...
LOCAL_MODULE_PATH := $(TARGET_OUT_DATA_APPS)
...
...
LOCAL_MODULE_PATH := $(TARGET_OUT)/data/app
...
I expect to install the APK into /data/app folder.
There might be a better way, but the way I handled was by including the .apk in a system directory ( not installing it, just use PRODUCT_COPY_FILES ).
Add in your device.mk code like this to copy the file:
PRODUCT_COPY_FILES += \
vendor/XXXXX/common/apps/MYApplication/MYApplication.apk:system/app/MYApplication.nm
Then modify Provision app ( which runs on first device boot ) to install that APK. The installation is done via PackageManager API. Check this answer, or similar.
I have an APK that contains java code and some .so files. I have built the APK in Android Studio and now this APK needs to be part of /system/app/ folder on my custom ROM.
Java code + .so = APK
To include it in system/app/, I am having the below build script in Android.mk file and calling it from device.mk file.
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE_TAGS := optional
LOCAL_MODULE := utility
LOCAL_MODULE_CLASS := APPS
LOCAL_CERTIFICATE := platform
LOCAL_SRC_FILES := utility.apk
include $(BUILD_PREBUILT)
After building the image, I find my APK crashing, and the log says "Cannot link executable" and all .so files seeems to be missing.
However, the APK works if I use adb install utility.apk.
Can someone tell me what is that I am missing in the buildscript that is causing .so files not being available.
P.S.: I searched inside /data/data/com.org.utility/, /system/lib/ folders, but no .so files were found.
But if I use adb install, .so files are found inside /data/data/com.org.utility/lib/x86/ folder.
I don't remember in L or M, there is a bug in the build system.
The so in the apk which is built into system/app or system/priv-app cannot release into the system. But the third party app can release there libs by PackageManagerService.
One solution:
1. Released the so in the apk manually.
2. Add so related to the Android.mk, for example:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := test
LOCAL_SRC_FILES := libtest.so
include $(PREBUILT_SHARED_LIBRARY)
Add this module name to PRODUC_PACKAGES micro.
These so in your app will be built to your system/lib or lib64.
Good luck.
I've downloaded (using repo) the Android 4.0 OS source code (from here - http://source.android.com/). I'm trying to add a new external project (in external/ for example external/libhelloworld) to the build system so that it is built into the system image. In that project I would like to deploy a shell script and have it keep it's permissions which are rwxr-xr-x but when I build it and load the emulator I see the file permissions have been changed to rw-r--r--. I am deploying the script to /etc. My Android.mk file looks like this
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := libhelloworld
LOCAL_MODULE_TAGS := optional
LOCAL_MODULE_SRC := helloworld.c
include $(BUILD_SHARED_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := myscript.sh
LOCAL_MODULE_TAGS := optional
LOCAL_MODULE_SRC := $(LOCAL_MODULE)
LOCAL_MODULE_CLASS := EXECUTABLES
LOCAL_MODULE_PATH := $(TARGET_OUT)/etc/helloscripts
include $(BUILD_PREBUILT)
I see the script permissions are preserved when it is copied into the intermediates area but then the permissions are changed at some point after that in the build process. Any idea why the script permissions are not being preserved when it gets added into the system image? Is there something I'm missing from my Android.mk?
System image filesytem modifications you can change in this file:
system/core/include/private/android_filesystem_config.h
Try to change permissions there. If you have problems, please, post here.