Make app in Android source compile to system/app - android

I'm trying to learn how to compile an app in android source. The app is just a simple hello world application. I followed instructions from Making an app in the Android Source compile into system/app instead of data/app? and a couple of other sources. But when I make the application the apk file is written to obj/APPS with suffix intermediates instead of system/app and fails to show up in the emulator when I boot up. Please find below the Android.mk file.
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE_TAGS := tests
LOCAL_MODULE_PATH := system/app
LOCAL_UNINSTALLABLE_MODULE := true
LOCAL_SDK_VERSION := current
LOCAL_PACKAGE_NAME := MyApplication
LOCAL_STATIC_JAVA_LIBRARIES := android-support-v4
LOCAL_STATIC_JAVA_LIBRARIES += android-support-v7-appcompat
LOCAL_STATIC_JAVA_LIBRARIES += android-support-v7-gridlayout
LOCAL_STATIC_JAVA_LIBRARIES += android-support-v13
LOCAL_STATIC_JAVA_LIBRARIES += android-support-design
LOCAL_SRC_FILES := $(call all-java-files-under, src)
LOCAL_RESOURCE_DIR := $(LOCAL_PATH)/res
LOCAL_RESOURCE_DIR += prebuilts/sdk/current/support/v7/appcompat/res
LOCAL_RESOURCE_DIR += prebuilts/sdk/current/support/v7/gridlayout/res
LOCAL_RESOURCE_DIR += prebuilts/sdk/current/support/design/res
LOCAL_CERTIFICATE := platform
LOCAL_AAPT_FLAGS := --auto-add-overlay
LOCAL_AAPT_FLAGS += --extra-packages android.support.v7.appcompat:android.support.v7.gridlayout
include $(BUILD_PACKAGE)
##################################################
include $(CLEAR_VARS)
include $(BUILD_MULTI_PREBUILT)
# Use the following include to make our test apk.
include $(call all-makefiles-under,$(LOCAL_PATH))
I make the application by going to the application directory in packages/apps and doing 'mm'. Is there anything I'm missing here?

Find out the BoardConfig.mk and add this :
PRODUCT_PACKAGES += MyApplication
AOSP build system will build every Android.mk, but only packages defined in BoardConfig will be put into the final product path.

you have to add the app module into the PRODUCT_PACKAGE from the devices/"your preferred vendor"/"device_name"/aosp_"device Name".mk file
It should look something like the following
$(call inherit-product, device/lge/hammerhead/full_hammerhead.mk)
PRODUCT_NAME := aosp_hammerhead
PRODUCT_PACKAGES += \
Launcher3 \
MyApplication \

It has little bit changed. Aosp checks /device/"vendor"/"your_device"/"your_platform"/base.mk file for compiling and /device/"vendor"/"your_device"/common/base.mk for installing apk to /out/target/product/"your_device/system/app/"
You should add your app name to both files.
In my case; aosp/device/qcom/qssi/base.mk to compile,
aosp/device/qcom/common/base.mk to install output(apk) to /out/target/product/msm8953/system/app/

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)

How to use constraint-layout during AOSP build without including external .aar and .jar

I'm trying to build my java based android app through building as a module inside AOSP source. My app uses android.support.constraint.ConstraintLayout. But, I didn't find a direct way to include constraint-layout dependency in my Android.mk.
I've put my project under AOSP_ROOT/packages/apps and tried with this Android.mk:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE_TAGS := optional
LOCAL_PRIVILEGED_MODULE := true
LOCAL_PACKAGE_NAME := MyApp
LOCAL_PRIVATE_PLATFORM_APIS := true
LOCAL_SRC_FILES := $(call all-java-files-under, java)
LOCAL_MANIFEST_FILE := AndroidManifest.xml
LOCAL_AAPT_FLAGS := \
--auto-add-overlay \
--extra-packages android.support.constraint
LOCAL_STATIC_JAVA_LIBRARIES := \
android-common \
android-support-v4 \
android-support-constraint-layout-solver
LOCAL_STATIC_JAVA_AAR_LIBRARIES := \
android-support-constraint-layout
include $(BUILD_PACKAGE)
But, this comes up with build error:
ninja: error: 'out/target/common/obj/JAVA_LIBRARIES/android-support-constraint-layout_intermediates/aar/classes.jar', needed by 'out/target/common/obj/APPS/MyApp_intermediates/AndroidManifest.xml', missing and no known rule to make it
20:57:54 ninja failed with: exit status 1
What I understand - it is searching for classes.jar which could be built from .aar file, but it is missing. However, the answer here solves the issue: How to include constraint layout library in an AOSP project
But, the problem is, that answer suggests to add external constraint-layout.aar and constraint-layout-solver.jar within my project libs directory.
My question, is it possible to add constraint-layout support in my project using built-in library inside AOSP without adding external .aar and .jar to my project?
Anyways, I've found the solution. There is no need to include the constraint-layout in the project libs as extra library.
To solve the issue, in Android.mk we need to add one extra line:
LOCAL_USE_AAPT2 := true
And also use LOCAL_STATIC_ANDROID_LIBRARIES instead of LOCAL_STATIC_JAVA_AAR_LIBRARIES.
This is the working Android.mk:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE_TAGS := optional
LOCAL_PRIVILEGED_MODULE := true
LOCAL_PACKAGE_NAME := MyApp
LOCAL_PRIVATE_PLATFORM_APIS := true
LOCAL_USE_AAPT2 := true
LOCAL_SRC_FILES := $(call all-java-files-under, java)
LOCAL_MANIFEST_FILE := AndroidManifest.xml
LOCAL_AAPT_FLAGS := \
--auto-add-overlay \
--extra-packages android.support.constraint
LOCAL_STATIC_ANDROID_LIBRARIES:= \
android-support-constraint-layout
LOCAL_STATIC_JAVA_LIBRARIES := \
android-common \
android-support-v4 \
android-support-constraint-layout-solver
include $(BUILD_PACKAGE)

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 include appcompat_v7 in Android.mk file

I want my app to be built with Android Source code. How to include appcompat_v7 in Android.mk file and where to place the appcompat_v7 folder in source code. I am using the following code,
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
LOCAL_STATIC_JAVA_LIBRARIES := \appcompat_v7
# Include all java files.
LOCAL_SRC_FILES := $(call all-java-files-under, src)
LOCAL_PACKAGE_NAME := MyPackage
include $(BUILD_PACKAGE)
I am getting error
make: No rule to make target 'out/target/common/obj/JAVA_LIBRARIES/\appcompat_v7_intermediates/javalib.jar', needed by 'out/target/common/obj/APPS/MyPackage_intermediates/classes-full-debug.jar'. Stop.
Anyone Please help. Thanks in advance.
I was able to build a package that includes appcompat using the following Android.mk
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_PACKAGE_NAME := MySuperAwesomeApp
LOCAL_STATIC_JAVA_LIBRARIES := android-support-v4
LOCAL_STATIC_JAVA_LIBRARIES += android-support-v7-appcompat
LOCAL_STATIC_JAVA_LIBRARIES += android-support-v7-gridlayout
LOCAL_STATIC_JAVA_LIBRARIES += android-support-v13
LOCAL_SRC_FILES := $(call all-java-files-under, src)
LOCAL_RESOURCE_DIR := $(LOCAL_PATH)/res
LOCAL_RESOURCE_DIR += prebuilts/sdk/current/support/v7/appcompat/res
LOCAL_RESOURCE_DIR += prebuilts/sdk/current/support/v7/gridlayout/res
LOCAL_CERTIFICATE := platform
LOCAL_PRIVILEGED_MODULE := true
LOCAL_AAPT_FLAGS := --auto-add-overlay
LOCAL_AAPT_FLAGS += --extra-packages android.support.v7.appcompat:android.support.v7.gridlayout
include $(BUILD_PACKAGE)
Source: https://android.googlesource.com/platform/packages/apps/UnifiedEmail/+/android-5.0.1_r1/Android.mk
This code works for me, and I hope it can help! Copy the jar files in the libs of appcompat_v7 project to the libs directory of your project.
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
LOCAL_STATIC_JAVA_LIBRARIES := \
android-support-v4 \
android-support-v7-appcompat
<more jar could be added here>
LOCAL_SRC_FILES := $(call all-subdir-java-files)
LOCAL_PACKAGE_NAME := <The name of your App project>
LOCAL_RESOURCE_DIR := $(LOCAL_PATH)/res
LOCAL_RESOURCE_DIR += <The absolute path to your appcompat_v7 project>/res
LOCAL_CERTIFICATE := platform
LOCAL_PRIVILEGED_MODULE := true
LOCAL_AAPT_FLAGS := --auto-add-overlay
LOCAL_AAPT_FLAGS += --extra-packages android.support.v4:android.support.v7.appcompat <replace the _ with . for your all jar files>
include $(BUILD_PACKAGE)
I built my package in command line along with Android source code and had hard time to include the v7 appcompat. To me, copying android-support-v7-appcompat.jar to libs and changing Android.mk as others posted above did not solve my problem. I finally figured out that I need build that v7 appcompat first.
Go to PATH/TO/frameworks/support/v7/appcompat and build it first.
No need to copy appcompat.jar to libs. Make your Android.mk like two posts above and it should work.

Categories

Resources