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:


Leave a Reply

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