Add prebuilt apk to AOSP build - android

I tried to include a prebuilt google apk (with no .so file) to my marshmallow AOSP build based on the information found in this link as follows:
In my vendor/manufacturer/device/proprietary/system/app, I created a folder named 'Testapk'.
I saved two files in this 'Testapk' folder, the apk ('Testapk.apk') and an Android.mk file which contains the following instructions:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE_TAGS := optional
LOCAL_MODULE := Testapk
LOCAL_SRC_FILES := $(LOCAL_MODULE).apk
LOCAL_MODULE_CLASS := APPS
LOCAL_MODULE_SUFFIX := $(COMMON_ANDROID_PACKAGE_SUFFIX)
LOCAL_CERTIFICATE := PRESIGNED
include $(BUILD_PREBUILT)
I added the following instruction in my vendor/manufacturer/device/vendor_device.mk :
PRODUCT_PACKAGES += \
Testapk
When making the AOSP build, I get the following error:
make: *** No rule to make target `/Testapk', needed by `out/target/product/mako/obj/APPS/Books_intermediates/Testapk.apk'. Stop.
#### make failed to build some targets (01:00 (mm:ss)) ####

The problem with my Android.mk file was that it had trailing spaces on each line. Everything worked fine after I deleted these trailing spaces.

after the \ the "testapk" should be on a new line.
PRODUCT_PACKAGES += \ Testapk

Related

Does Android.mk require AndroidManifest.xml?

I am trying to build my app as a part of the AOSP and realized that the Android.mk file does not take the path of the AndroidManifest.xml as input.
How can the mm command build the app with just the java files and the resources?
From where does the Android make get the information contained in AndroidManifest.xml?
Note:
Currently, my app is building with mm but has a smaller size (1MB vs 5MB) and does not show up on the device after adb install. Maybe this will fix it.
My Android.mk file for any reference
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_STATIC_ANDROID_LIBRARIES += \
android-arch-lifecycle-extensions \
android-support-v7-recyclerview \
android-support-v7-appcompat \
android-support-constraint-layout \
# Build all java files in the java subdirectory
#LOCAL_SRC_FILES := $(call all-subdir-java-files)
#Commented line just made a ~17kB apk file
LOCAL_SRC_FILES := $(call all-java-files-under, app/src/main/java)
LOCAL_RESOURCE_DIR += $(LOCAL_PATH)/app/src/main/res
# Name of the APK to build
LOCAL_PACKAGE_NAME := LocalPackage
LOCAL_SDK_VERSION := current
#Otherwise build failing
# Tell it to build an APK
include $(BUILD_PACKAGE)

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.

Add androidx.viewpager2 to android.mk file

Trying to add androidx.viewpager2 to android.mk as below:
LOCAL_STATIC_ANDROID_LIBRARIES += \
androidx.viewpager2_viewpager2
Not able to build code using MMA command and gives below error.
ninja: error:
'out/target/common/obj/JAVA_LIBRARIES/androidx.viewpager2_viewpager2_intermediates/package-res.apk',
needed by
'out/target/product/apps/obj/APPS/app_intermediates/package-res.apk',
missing and no known rule to make it
05:31:24 ninja failed with: exit status 1
failed to build some targets (05:38 (mm:ss))
How can I add androidx.viewpager2 to Android.mk Makefile.
You'll have to add viewpager2-1.0.0.aar into LOCAL_STATIC_JAVA_LIBRARIES (or LOCAL_STATIC_JAVA_AAR_LIBRARIES).
Add following blocks to support/sync with .AAR library file in Android.mk file
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
.
.
LOCAL_PACKAGE_NAME := App_Name
.
LOCAL_PRIVATE_PLATFORM_APIS := true
.
LOCAL_STATIC_JAVA_LIBRARIES := AAR_file-alias
.
include $(BUILD_PACKAGE)
include $(CLEAR_VARS)
LOCAL_PREBUILT_STATIC_JAVA_LIBRARIES := AAR_file-alias:lib_path/AAR_file.aar
include $(BUILD_MULTI_PREBUILT)

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)

creating shared library using prebuilt static library using Android.mk

I am trying to build a shared library using prebuilt static library, the respective Android.mk file is below.
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
#Include kerne headers in a proper way later on
#LOCAL_C_INCLUDES:= $(LOCAL_PATH)/../../../../kernel/include
LOCAL_MODULE := sensors.$(TARGET_BOARD_PLATFORM)
LOCAL_MODULE_TAGS := optional
LOCAL_PRELINK_MODULE := false
LOCAL_MODULE_PATH := $(TARGET_OUT_SHARED_LIBRARIES)/hw
LOCAL_STATIC_LIBRARIES := LibFusion_ARM_cpp
#LOCAL_LDFLAGS := $(LOCAL_PATH)/LibFusion_ARM_cpp.a
LOCAL_SHARED_LIBRARIES := liblog libcutils
#include any shared library dependencies
LOCAL_LDFLAGS := $(LOCAL_PATH)/libimu.a
LOCAL_PRELINK_MODULE := false
LOCAL_SRC_FILES := sensors_u8500.cpp
include $(BUILD_SHARED_LIBRARY)
The files present in the folder is
Android.mk , LibFusion_ARM_cpp.a , libimu.a , MEMSAlgLib_eCompass.h , sensors_u8500.cpp
The error what I am getting while building is below,
**make: *** No rule to make target `out/target/product/u8500/obj/STATIC_LIBRARIES/LibFusion_ARM_cpp_intermediates/LibFusion_ARM_cpp.a', needed by `out/target/product/u8500/obj/SHARED_LIBRARIES/sensors.montblanc_intermediates/LINKED/sensors.montblanc.so'. Stop.**
What is the issue here?
Unable to build the shared library. I mean unable to generate libsensor.so file. facing the above mentioned error. ** make: * No rule to make target
It seems that the build system cannot find LibFusion_ARM_cpp.a. AFAIK, you have to first specify a pre-built library module using PREBUILT_STATIC_LIBRARY with LibFusion_ARM_cpp.a set as LOCAL_SRC_FILES and LOCAL_MODULE as LibFusion_ARM_cpp. This will basically copy the specified static library to the default directory the build system searches through for all of the necessary modules.
I did two things to understand the case:
A. In the above shown make file, I added the below so as to ensure that this .a file gets copied into the build.
include $(CLEAR_VARS)
LOCAL_MODULE := LibFusion_ARM
LOCAL_SRC_FILES := LibFusion_ARM_cpp.a
include $(BUILD_STATIC_LIBRARY)
When I build it using mm -n, command I see this strange statement rm -f ... of the LibFusion_ARM.a. Of course the build fails saying it's not able to locate the STATIC LIB.
mkdir -p out/target/product/u8500/obj/STATIC_LIBRARIES/LibFusion_ARM_intermediates/
rm -f out/target/product/u8500/obj/STATIC_LIBRARIES/LibFusion_ARM_intermediates/LibFusion_ARM.a
echo "target StaticLib: LibFusion_ARM (out/target/product/u8500/obj/STATIC_LIBRARIES/LibFusion_ARM_intermediates/LibFusion_ARM.a)"
mkdir -p out/target/product/u8500/obj/SHARED_LIBRARIES/sensors.montblanc_intermediates/LINKED/
.
.
Why does this deletion happens? I am not sure. This is causing the problem. Please provide suggestions.
B. I added the below lines in the make file:
include $(CLEAR_VARS)
LOCAL_MODULE := LibFusion_ARM
LOCAL_SRC_FILES := LibFusion_ARM_cpp.a
include $(PREBUILT_STATIC_LIBRARY)
I see the below error:
make: *** No rule to make target `out/target/product/u8500/obj/STATIC_LIBRARIES/LibFusion_ARM_intermediates/LibFusion_ARM.a', needed by `out/target/product/u8500/obj/SHARED_LIBRARIES/sensors.montblanc_intermediates/LINKED/sensors.montblanc.so'.
Stop.
Clearly in the second case, the file LibFusion_ARM is not getting copied (even obj/STATIC_LIBRARIES/LibFusion_ARM_intermediates directory is not created).
Needless to emphasis, if I manually copy the file LibFusion_ARM_cpp.a as LibFusion_ARM.a then the build goes through.

Categories

Resources