When i add app priv-app phone not booting - android

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

Related

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

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)

Include .so in android.mk system app android

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.

integrate google apps to the build to be installed in /data/app

i try to make my own rom, and I want add google-apps to the build to be installed in /data/app
this is the steps :
1 - create new folder called "gapps" in vendor/ dir
2- in "gapps" add data/app/Youtube/app/youtube.apk,
3- create android.mk file in "gapps" folder with this content
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := YouTube
LOCAL_SRC_FILES := data/app/YouTube/YouTube.apk
LOCAL_MODULE_PATH := $(TARGET_OUT_DATA_APPS)
LOCAL_MODULE_CLASS := APPS
LOCAL_MODULE_OWNER := GOLDROM
LOCAL_MODULE_TAGS := optional
LOCAL_CERTIFICATE := PRESIGNED
LOCAL_MODULE_SUFFIX := $(COMMON_ANDROID_PACKAGE_SUFFIX)
include $(BUILD_PREBUILT)
4 - go to the build dir in the android root files build/target/product/core.mk and add YouTube to the PRODUCT_PACKAGES var
5- build, flash, but youtube not found.
plz correct me , if i made any mistak. :)
solution is to add your module to PRODUCT_PACKAGES var
rootAndroid/build/target/product/generic_no_telephony.mk
and then youtube will work fine in /data as a user app
but its still a not clean solution.

Build Android from Source - Add Prebuilt App with Shared Library

i've build my own androidrom from source and modified a few things.
But now i wan't to add an prebuilt .apk to the project,
read that i should make an folder in /packages/apps/
and add the .apk and an Android.mk to it with following code
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := <folder name>
LOCAL_SRC_FILES := $(LOCAL_MODULE).apk
LOCAL_MODULE_CLASS := APPS
LOCAL_MODULE_SUFFIX := $(COMMON_ANDROID_PACKAGE_SUFFIX)
LOCAL_CERTIFICATE := PRESIGNED
include $(BUILD_PREBUILT)
and the added the module to the in my case /device/sony/honami/full_honami.mk
when i now run brunch i get the error after some time that no rule for target *
so i tried some changes but nothing works for me and i can't find something where there write something other than this ...
so i added the .apk to the /vendor/cm/prebuilts folder and in the *.mk where i found the other .apks where copyed to the device i added my app and run brunch without an error.
But when i now start the app, which is on the device, it crash.
Via Logcat i found out that this apk have some .so files in it and that it can't find them.
This is because i only copied the app not the .so files in the lib directory. But i can't find some solution for my problem.
Should i now extract the .so file and copy it like the .apk to the path the app looks? or is there a better solution for doing this?
Cheers
Moritz
AOSP build system handles the shared libraries differently from Eclipse-ADT.
You will need to extract that .so from your apk and create an Android.mk to it.
To extract the .so, just unzip the apk and get it from libs folder.
Here is an example for the Android.mk to libfoo.so shared library:
LOCAL_PATH:= $(call my-dir)
# prebuilt shared library
include $(CLEAR_VARS)
LOCAL_MODULE := libfoo
LOCAL_SRC_FILES := libfoo.so
LOCAL_MODULE_SUFFIX := .so
LOCAL_MODULE_CLASS := SHARED_LIBRARIES
LOCAL_MODULE_PATH := $(TARGET_OUT)/lib
LOCAL_MODULE_TAGS := optional
include $(BUILD_PREBUILT)

How do I preserve file permissions in a custom external project added to Android AOSP?

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.

Categories

Resources