Dynamically adding all apk's inside directory to AOSP system image - android

I'm having trouble adding a set of prebuilt apk's to my custom build of AOSP. What I am trying to accomplish is to allow developers of these apps to simply drop them in a directory under source control and the next CI build of the image will just include those applications. I have tried this using the code below to add all apks inside the included_apks directory but it's not working as expected.
define add_included_apks
include $(CLEAR_VARS)
LOCAL_MODULE := $(1:included_apks/%.apk=%)
LOCAL_MODULE_TAGS := eng userdebug
LOCAL_MODULE_CLASS := APPS
LOCAL_MODULE_SUFFIX := $(COMMON_ANDROID_PACKAGE_SUFFIX)
LOCAL_SRC_FILES := $1
LOCAL_CERTIFICATE := PRESIGNED
include $(BUILD_PREBUILT)
endef
APKS := $(call find-subdir-subdir-files, included_apks, '*.apk')
$(foreach item, $(APKS), $(eval $(call add_included_apks, $(item))))
The problem with this approach seems to be inside the add_included_apks function and how it is evaluated. When I print out $(1:included_apks/%.apk=%) it's the correct value but if I print out LOCAL_MODULE it's the last value set on it before this loop even though I'm calling include $(CLEAR_VARS). And in the end the module is not included in the system image. Am I misunderstanding how a foreach call works in a make file?
Edit Answer is correct, but the real AOSP bug is this:
The LOCAL_MODULE_TAGS := eng userdebug should be LOCAL_MODULE_TAGS := eng debug to be included in a userdebug build variant. The make syntax was correct for what I was attempting to do.

When you want to print inside a define like that you have to escape the $ with another $.
define add_included_apks
include $(CLEAR_VARS)
LOCAL_MODULE := $(1:included_apks/%.apk=%)
$$(error $$(LOCAL_MODULE))
LOCAL_MODULE_TAGS := eng userdebug
LOCAL_MODULE_CLASS := APPS
LOCAL_MODULE_SUFFIX := $(COMMON_ANDROID_PACKAGE_SUFFIX)
LOCAL_SRC_FILES := $1
LOCAL_CERTIFICATE := PRESIGNED
include $(BUILD_PREBUILT)
endef

'LOCAL_MODULE_TAGS := eng debug' will not include this in user builds, but eng and userdebug. If you want to have it included in user builds. It has to be 'optional' and your device/.../BoardConfig.mk has to add those into:
PRODUCT_PACKAGES += your_local_module1 \
your_local_module2 end so on...

Related

prebuil apks not getting added in aosp build

I am trying to add a prebuilt apk to aosp source but the apk is not geting added.
Android.mk details is like
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE_TAGS := optional
LOCAL_UNINSTALLABLE_MODULE := true
LOCAL_MODULE_PATH := $(TARGET_OUT_APPS)
LOCAL_MODULE := vlc-player
LOCAL_SRC_FILES := $(LOCAL_MODULE).apk
LOCAL_BUILT_MODULE_STEM := package.apk
LOCAL_MODULE_CLASS := APPS
LOCAL_MODULE_SUFFIX := $(COMMON_ANDROID_PACKAGE_SUFFIX)
LOCAL_CERTIFICATE := platform
LOCAL_MODULE_PATH := $(TARGET_OUT_DATA)
include $(BUILD_PREBUILT)
I have also added entry in core.mk under
PRODUCT_PACKAGES +=
vlc-player
but the apk is not added to the build
Remove the flag LOCAL_MODULE_TAGS := optional and try calling the PRODUCT_PACKAGES += vlc-player in your device specific makefile, for example in
device/google/blueline/device.mk
Also manually verify the out directory by running a separate make call like , make vlc if your module is working.

AOSP add prebuilt APK - error unknown target

I'm making a personal build of LineageOS 17.0 that I want to include a number of pre-built APKs in. To achieve this, I have a separate folder "vendor/apps" which has two files apps-vendor.mk and Android.mk, and a sub-folder "app" which I store the APK files. This was with the help of this thread Add prebuilt apk to AOSP build.
Now, whilst I have been successful with including a number of APKs such as Blokada, FDroid, every now and then I come across an APK that I simply can't add into the build, such as TotalCommander.
If I go through the normal build process, it simply doesn't get added. If I use e.g. "mma TotalCommander" I receive an error saying "FAILED: ninja: unknown target 'TotalCommander'".
The following is what I have included in my apps-vendor.mk file:
Blokada \
FDroid \
F-DroidPrivilegedExtension \
VLC \
WaveUp \
YouTubeVancedMicroG \
YouTubeVanced \
TotalCommander
This is an excerpt from my Android.mk file:
# Custom added apps
include $(CLEAR_VARS)
LOCAL_MODULE_TAGS := optional
LOCAL_MODULE := Blokada
LOCAL_CERTIFICATE := PRESIGNED
LOCAL_SRC_FILES := app/Blokada.apk
LOCAL_MODULE_CLASS := APPS
LOCAL_MODULE_SUFFIX := $(COMMON_ANDROID_PACKAGE_SUFFIX)
include $(BUILD_PREBUILT)
include $(CLEAR_VARS)
LOCAL_MODULE_TAGS := optional
LOCAL_MODULE := FDroid
LOCAL_CERTIFICATE := PRESIGNED
LOCAL_SRC_FILES := app/FDroid.apk
LOCAL_MODULE_CLASS := APPS
LOCAL_MODULE_SUFFIX := $(COMMON_ANDROID_PACKAGE_SUFFIX)
include $(BUILD_PREBUILT)
include $(CLEAR_VARS)
LOCAL_MODULE_TAGS := optional
LOCAL_MODULE := TotalCommander
LOCAL_CERTIFICATE := PRESIGNED
LOCAL_SRC_FILES := app/TotalCommander.apk
LOCAL_MODULE_CLASS := APPS
LOCAL_MODULE_SUFFIX := $(COMMON_ANDROID_PACKAGE_SUFFIX)
include $(BUILD_PREBUILT)
etc ...
I have tried a few different things, such as swapping the APK filename for one that is working, trying a different module name such as TC, etc, all of which give the same result.
I feel silly, but the issue was this. I originally had the folder directly under vendor, but then I moved the folder to a parent directory and symlinked it. Building does not work properly with symlinks like this. I still detects the vendor-apps.mk file, and when it is changed, but it doesn't actually add any rules.

How to build custom system privilege app in aosp

I am trying to implement custom system app which has system privilege. I searched about it and I learned to make system app built in system image build result needs to be placed in system/app
First I put my custom app's java file, resource file, cpp file as in this below directory(packages/apps).
And I made Android.mk file like this below.
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
$(info Ojt System Module)
#LOCAL_MODULE_CLASS := APPS
#LOCAL_MODULE_SUFFIX := $(COMMON_ANDROID_PACKAGE_SUFFIX)
LOCAL_PACKAGE_NAME := OjtTestApp
LOCAL_CERTIFICATE := platform
LOCAL_PRIVILEGED_MODULE := true
LOCAL_UNINSTALLABLE_MODULE := true
LOCAL_SRC_FILES := $(call all-java-files-under,src)
LOCAL_STATIC_ANDROID_LIBRARIES := \
android-support-v13 \
android-support-v4 \
android-support-compat \
android-support-v7-appcompat \
android-support-v7-gridlayout
LOCAL_JNI_SHARED_LIBRARIES := libojt
LOCAL_RESOURCE_DIR := $(LOCAL_PATH)/res
LOCAL_SDK_VERSION := current
LOCAL_PROGUARD_ENABLED := disabled
LOCAL_MODULE_TAGS := optional
LOCAL_MODULE_PATH := $(TARGET_OUT_APPS)
include $(BUILD_PACKAGE)
#include $(BUILD_PREBUILT)
include $(call all-makefiles-under,$(LOCAL_PATH))
I also putted package name in aosp_sailfish.mk(device/google/marlin/aosp_sailfish.mk) file like this below.
PRODUCT_PACKAGE += OjtTestApp
After that I build my app by make OjtTestApp and build was completed without error. I tried to make apk file as in this post to system/app so that my custom app can built in system image but It keeps gave me following output(obj/APPS).
[100% 8/8] target Package: OjtTestApp (out/target/product/sailfish/obj/APPS/OjtTestApp_intermediates/package.apk)
Please help me I can't find error in my Android.mk file.
You don't need to go to that length. Build your apk normally don't sign it or sign it with system certificate. Now include the apk by writing a rule in as below in platform specific device.mk file
PRODUCT_PACKAGES += \
AppName
Sample mk file
LOCAL_PATH := $(call my-dir)
####################################
$(warning dont't include $(call my-dir)/Android.mk )
include $(CLEAR_VARS)
LOCAL_MODULE := <your app name>
LOCAL_MODULE_TAGS := optional
LOCAL_CERTIFICATE := PRESIGNED #If you have signed already using system key
LOCAL_PRIVILEGED_MODULE := true
LOCAL_MODULE_CLASS := APPS
LOCAL_MODULE_SUFFIX := $(COMMON_ANDROID_PACKAGE_SUFFIX)
LOCAL_SRC_FILES := $(LOCAL_MODULE).apk
#LOCAL_REQUIRED_MODULES := libnative-lib
include $(BUILD_PREBUILT)
For full privilege use
android:sharedUserId="android.uid.system" in Manifest

AOSP my app is not included in system build

I'm building a custom ROM and would like to include a simple launcher I built as a system app. Here is my Android.mk
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
# General
LOCAL_PACKAGE_NAME := Tott
LOCAL_SDK_VERSION := current
LOCAL_MODULE_TAGS := optional
LOCAL_PROGUARD_ENABLED := disabled
# To make system app
LOCAL_CERTIFICATE := platform
LOCAL_UNINSTALLABLE_MODULE := true
LOCAL_PRIVILEGED_MODULE := true
LOCAL_OVERRIDES_PACKAGES := Home Launcher2 Launcher3
# src/res files
LOCAL_SRC_FILES := $(call all-java-files-under, src)
LOCAL_RESOURCE_DIR := $(LOCAL_PATH)/res
# libraries
LOCAL_STATIC_JAVA_LIBRARIES := android-support-v7-appcompat
#flags
LOCAL_AAPT_FLAGS := \
--auto-add-overlay \
--extra-packages android.support.v7.appcompat
include $(BUILD_PACKAGE)
I have placed the Android.mk, AndroidManifest.xml, res folder, and src (containing java) in a directory called Tott which has been placed in [source]/packages/apps. I've also added Tott to PRODUCT_PACKAGES at [source]/build/target/product/core.mk
When I build the android system.img, it says that that it is including [source]/packages/apps/Tott/Android.mk in terminal but my app never shows in [source]/out/target/product/vender/system/app or priv-app. I'm also able to build my app successfully by simply running make Tott at [source].
What am I doing wrong here????
Thanks
Comment out LOCAL_SDK_VERSION and LOCAL_UNINSTALLABLE_MODULE. I don't use those in my Android.mk files and I never have a problem.

How to solve Build Error:unhandled LOCAL_MODULE_CLASS "APPS"?

I want to add my pre-built APK to my AOSP build. I've created the following folders vendor/aaa/crespo and pasted my APK inside the folder. I've also created a make file to install my APK.
The make file is as follows:
$(call inherit-product, $(SRC_TARGET_DIR)/product/generic.mk)
include $(CLEAR_VARS)
LOCAL_MODULE_PATH := vendor/aaa/crespo/
LOCAL_MODULE_PATH := $(strip $(LOCAL_MODULE_PATH))
ifeq ($(LOCAL_MODULE_PATH),)
LOCAL_MODULE_PATH := $($(my_prefix)OUT$(partition_tag)_$(LOCAL_MODULE_CLASS))
ifeq ($(strip $(LOCAL_MODULE_PATH)),)
$(error $(LOCAL_PATH): unhandled LOCAL_MODULE_CLASS "$(LOCAL_MODULE_CLASS)")
endif
endif
# Module name should match apk name to be installed.
LOCAL_MODULE := test
LOCAL_SRC_FILES := $(LOCAL_MODULE).apk
LOCAL_MODULE_CLASS := APPS
LOCAL_MODULE_SUFFIX := $(COMMON_ANDROID_PACKAGE_SUFFIX)
LOCAL_MODULE_TAGS := optional
LOCAL_CERTIFICATE := PRESIGNED
include $(BUILD_PREBUILT)
Can anyone tell me what is wrong with the make file? In this make file, I want to tell the compiler to add my APK into the build. It builds fine but my app is not present in the installed-files.txt file.
Reading build script at github
LOCAL_MODULE_PATH := $(strip $(LOCAL_MODULE_PATH))
ifeq ($(LOCAL_MODULE_PATH),)
LOCAL_MODULE_PATH := $($(my_prefix)OUT$(partition_tag)_$(LOCAL_MODULE_CLASS))
ifeq ($(strip $(LOCAL_MODULE_PATH)),)
$(error $(LOCAL_PATH): unhandled LOCAL_MODULE_CLASS "$(LOCAL_MODULE_CLASS)")
endif
endif
It is your path that's wrong. If Android.mk is at the same directory, I don't think you need to put path in front of it. By the way you are also not setting LOCAL_CERTIFICATE - I don't know if necessary but majority seems to set it.
In my case it helped to include Android.mk with definitions via macro all-makefiles-under:
include $(call all-makefiles-under, $(LOCAL_PATH))
Problem occurred when i include Android.mk directly.

Categories

Resources