Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I add an application in AOSP?

We are trying to develop a custom ROM using AOSP's master branch. We have successfully built and run the compiled image on the emulator provided by AOSP. Now we are trying to add an application in the AOSP so that the AOSP branch compiles and runs with the application present in it, that means when we run the android version our newly added application will act as a default/system application.

We have tried doing that using following steps, but have failed:

  1. Place the App_name folder to /packages/apps
  2. Add Android.mk to /packages/apps/App_name/
  3. Add App_name entry to /build/target/product/core.mk PRODUCT_PACKAGES := \ ... \ SomeApp \ App_name

Note: App_name is the application folder that is developed using android studio and is present the Android-Studio Projects folder.

After performing these steps we compile the entire source code/AOSP and eventually the compilation fails.

Could someone please help me out??

like image 516
Komal Deolalkar Avatar asked Jan 07 '18 13:01

Komal Deolalkar


1 Answers

For adding a default application to AOSP , You should create a directory with arbitrary name in packages/apps (name of directory doesn't matter) , then you should put necessary code and resources in it . Notice AOSP build system doesn't use Gradle ,hence you don't need to copy gradle build files (like build.gradle and setting.gradle and etc).

For a typical app you should create these directories :

  • src : place your java codes here .
  • res : place your resources directory for examle drawable , layout , ...
  • assets : if your project has any assests file , place them in this folder

Your AndroidManifest.xml file should be added in top of your directory.After placing your code and resources , create an Android.mk file and write the following lines in it :

LOCAL_PATH:= $(call my-dir)

include $(CLEAR_VARS)

LOCAL_PACKAGE_NAME := <Name of your app>

LOCAL_SDK_VERSION := current

LOCAL_SRC_FILES := $(call all-java-files-under, src)

# Include libraries

LOCAL_JAVA_LIBRARIES := <Java lib dependencies>

LOCAL_STATIC_JAVA_LIBRARIES := android-common

LOCAL_STATIC_JAVA_LIBRARIES += android-support-v4

LOCAL_STATIC_JAVA_LIBRARIES += android-support-v7-appcompat

LOCAL_RESOURCE_DIR := $(LOCAL_PATH)/res

LOCAL_ASSETS_DIR := $(LOCAL_PATH)/assets

LOCAL_AAPT_FLAGS := --auto-add-overlay

LOCAL_AAPT_FLAGS += --extra-packages android.support.v7.appcompat

include $(BUILD_PACKAGE)
  • LOCAL_PACKAGE_NAME is name of your app (for examle camera , app1 , ...) ,you should add this name to /build/target/product/core.mk (no folder name , folder name is not important) .

  • LOCAL_SRC_FILES is pointer to Java codes.

  • LOCAL_JAVA_LIBRARIES : if your project has java lib dependency , reference to it here.

  • LOCAL_RESOURCE_DIR is address of res directory

  • LOCAL_ASSETS_DIR is address of assets directory

Finally build your app and add it to system image . use these commands

make <name of your app>
make snod

<name of your app> is value of LOCAL_PACKAGE_NAME in your Android.mk file. You don't need to build whole AOSP build tree using something like make -j8 . Just build your app and add it to system image. Default applications are placed in read only system partition.

like image 176
ofskyMohsen Avatar answered Sep 18 '22 21:09

ofskyMohsen