This post details about how you can integrate your Android application as part of Android OpenSource Build system to get it compiled using command line. Normally Android applications are developed using Android Studio and it generates build.gradle to configure and compile the application, but when you want to get this same application compiled as part of AOSP project, you need to write Android.mk, change the directory structure to match with AOSP directory structure and get this app compiled from command line. This post has sample Android.mk which we can use to compile the HelloWorld Application.

Implementation details

$ cd Android_AOSP $ mkdir packages/apps/HelloWorld Copy your java application source code to packages/apps/ e.g. HelloWorld $ cd packages/apps/HelloWorld Write an Android.mk as below, $ vim Android.mk LOCAL_PATH := $(call my-dir) include $(CLEAR_VARS) LOCAL_STATIC_JAVA_LIBRARIES := android-support-v4 LOCAL_MODULE_TAGS := optional LOCAL_SRC_FILES := $(call all-java-files-under, src) LOCAL_PACKAGE_NAME := HelloWorld LOCAL_CERTIFICATE := platform LOCAL_PRIVILEGED_MODULE := true LOCAL_PROGUARD_ENABLED := disabled include $(BUILD_PACKAGE) If you want to enable proguard optimizations by default, just remove the line LOCAL_PROGUARD_ENABLED := disabled from above. Resolving Errors 1) Error: This attribute must be localized. If you get error like below, packages/apps/HelloWorld/res/layout/activity_main.xml:12: error: Error: This attribute must be localized. (at ‘text’ with value ‘Advertise’).

Gotchas and common issues

  • Permission checks - verify user access rights and sudo privileges before executing system-level operations.

  • Environment configuration - double-check path variables and dependency versions to prevent runtime failures.

  • Backup safeguards - maintain configuration backups before applying system or database modifications.

Following these steps ensures clean configuration and reliable execution for compile android application as part of aosp source code.