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.
$ 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’).
Solution :
Change packages/apps/HelloWorld/res/layout/activity_main.xml as below,
android:text="@string/advertise"
and add this reference to res/values/string.xml:
<string name="advertise">Advertise</string>
Reference : Click the Link
Installing Android Application
$ ./out/host/linux-x86/bin/adb install application_name.apk
After Installing, or during installation you might get an error like, “Error : Parsing the package”, to resolve this you need to verify the ” minSdkVersion ” whether its compatible to API on your mobile or not, and correct the same or alternatively, change AndroidManifest.xml Like below to set to min. value.
<uses-sdk
– android:minSdkVersion=”11″
+ android:minSdkVersion=”1″^M
Reference : Click the Link