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 Android.mk 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 Android.mk file in the jni directory :

Create Android.mk 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 Android.mk 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 , ,

1 thought 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/core.mk”, but this didn’t seem to solve the issue. Do you have any suggestions?

Leave a Reply

Your email address will not be published. Required fields are marked *