AOSP – Creating a System Application

When we build a ROM for Android device we can add components on different layers. We can add daemons and libraries on the native layer, system services on the framework layer and system applications we want to build into the ROM (like the phone app, SMS, etc)

In this post, I will  cover the process to create a system application with java and native code (c++)

We will start with building and testing our application in Android Studio, then integrate the files into AOSP

Create an Android studio project with C++ support

Add class for native methods:

Implement the native code and add JNI_OnLoad function:

Add a simple button and test the native methods

Test your app on Android Studio emulator

Integrate The Code with AOSP

Create a directory app in ~/aosp/device/generic/goldfish (here you will store all Android applications built into the rom)

Add a generic file to call other makefiles in the subdirectories:

Create the following directory structure in app:

Add the following file to the activity_main.xml (res/layout):

and the string table to res/values/strings.xml:

Create file in the jni directory :

Create file in jnisamp directory:

Add the java and c++ files from your project

Add AndroidManifest.xml file to jnisamp directory:

build the rom and test your code. if you connect using adb you can see that the process gets a regular uid

Make Your Application Run with System Privileges

Add coreApp and sharedUserId to the manifest file:

Add the following vars to main file:

Build the rom and test your work

Now run the application, connect to the device using adb and run ps -A to see all the processes. You will see application run as system user:


Tagged , ,

6 thoughts on “AOSP – Creating a System Application

  1. Hello,
    Thanks for the post!

    I managed to compile and my app with the AOSP and push the apk onto the phone. I want to be able to make it so when I make the AOSP, my app also gets automatically compiled. So when I flash the phone, the app would appear on it. I added my package name under “PRODUCT_PACKAGES” in “build/target/product/”, but this didn’t seem to solve the issue. Do you have any suggestions?

    1. Are you adding the correct LOCAL_MODULE value in *.mk for PRODUCT_FLAVOR you are flashing on your device? Normally, PRODUCT_PACKAGES are added in device/(VENDOR_NAME)/(BOARD_VARIANT)/../ o

  2. Sorry, i meant to say PRODUCT_PACKAGES instead of LOCAL_MODULE

  3. Is there a way to make system app written in kotlin language?

    1. Sure thing, but you’ll have to make it as a prebuilt and use Gradle

  4. Hi Can you Send sample example

Leave a Reply

Your email address will not be published.