Include .so in android.mk system app android - 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.

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)

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)

Error adding prebuilt apk with shared libraries to AOSP

I tried to add a prebuilt APK to my Android build. The APK contains several shared libraries (*.so files). It compiles without problem, but I still get an error from the app indicating that the libraries cannot be found.
Why could this be?
Here is the android.mk code:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := apkwithso
LOCAL_SRC_FILES := $(LOCAL_MODULE).apk
LOCAL_REQUIRED_MODULES := libx liby libz
LOCAL_MODULE_CLASS := APPS
LOCAL_MODULE_SUFFIX := $(COMMON_ANDROID_PACKAGE_SUFFIX)
LOCAL_CERTIFICATE := PRESIGNED
include $(BUILD_PREBUILT)
libx, y, z are my libx.so, liby.so, and libz.so
I also tried to copy the .so manually from the APK to the out lib directories but it didn't work.
I am compiling with Android 4.1.2 for Galaxy Nexus Maguro.
I've had this problem myself, the reason is that when APK files are included in a build they are essentially bypassing the installation process. This installation process is the point at which any shared libraries are extracted from the apk and put in the appropriate place, ergo if that never happens the libraries will not be available. This is because packages that are built from source during the AOSP build either have their prebuilt shared libraries included during that build process or their libraries are also built from source, and in either case those libraries are put in the appropriate place.
For this reason in addition to the apk module itself you should add the following in the same .mk file:
include $(CLEAR_VARS)
LOCAL_MODULE := libapkwithso
LOCAL_SRC_FILES := lib/libapkwithso.so # or wherever your so is
LOCAL_MODULE_TAGS := optional
LOCAL_MODULE_SUFFIX := .so
LOCAL_MODULE_CLASS := SHARED_LIBRARIES
include $(BUILD_PREBUILT)
Then add:
LOCAL_REQUIRED_MODULES := libapkwithso
BUILD_PREBUILT calls prebuild.mk script. The description of this script is the following:
Standard rules for copying files that are prebuilt
It does not tell that the application will be installed. So I think that is why your application cannot find the libraries.
The solution is to extract libraries from the package and copy them separately from the application. The details how to do this you can find here.
Files can also be be specified in aospSource:destinationOnImage format like this in the device-partial.mk when adding a custom vendor directory:
PRODUCT_COPY_FILES += \
vendor/your-custom-vendor/your-device/proprietary/libx.so:system/lib/libx.so
You can add pretty much anything you like here (other than .apk files), and it will be copied to your image.
My Instructions is not about your error! But it may be helpful for similar error
If you try to copy prebuilt apk using:
PRODUCT_COPY_FILES += $(LOCAL_PATH)/prebuilt/filename.apk
and you getting this error:
Prebuilt apk found in PRODUCT_COPY_FILES: ... , use BUILD_PREBUILT instead!. Stop.
You can remove this check my modify the file build/core/MakeFile and comment this lines:
define check-product-copy-files
$(if $(filter %.apk, $(call word-colon, 2, $(1))),$(error \
Prebuilt apk found in PRODUCT_COPY_FILES: $(1), use BUILD_PREBUILT instead!))
endef
by inserting # before each line
Too add multiple libraries to one apk one additional section (as in answer of Justin Buser) should be added for each separate library.

how to include external jar in android app for android custom build

I am trying to build a custom rom using android custom build project. I want to add one android application to it in which there is one external jar. But whenever I run 'mm' (i.e make) in /package/apps/myApp it gives error 41 in which it is not able to recognize classes and functions from that external jar. Although eclipse is recognizing that jar and app is running perfect in eclipse but 'mm' is not able to compile it. What should i do?
Any help is greatly appreciated.
Refer to the Android.mk file inside the Calculator app. It uses external jars.
I am also pasting a sample mk file that i used for my own app. You can use it:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE_TAGS := optional
LOCAL_MODULE_TAGS := tests
LOCAL_STATIC_JAVA_LIBRARIES := libguava libgcm android-support-v4
LOCAL_SRC_FILES := $(call all-java-files-under, src)
LOCAL_SDK_VERSION := current
LOCAL_PACKAGE_NAME := SampleApp
include $(BUILD_PACKAGE)
include $(CLEAR_VARS)
LOCAL_PREBUILT_STATIC_JAVA_LIBRARIES := libguava:guava-11.0.jar libgcm:gcm.jar
include $(BUILD_MULTI_PREBUILT)
include $(call all-makefiles-under,$(LOCAL_PATH)
libguava and libgcm are just two namespaces(You can use your own names) for the two jars:guava-11.0.jar and gcm.jar(I have used these jars in my project) respectively. I have kept the jars inside the project folder. If you have kept the jars inside libs folder use libguava:libs/guava-11.0.jar.Also, don't use mm. Use make, but don't do make clean before it else it will remove the entire build directory and start from scratch(take a lot of time) Please accept as solution if it works....Thanks

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