Developing System Apps using an emulator

Deploying systems apps on your AOSP emulator

Raju K
XRPractices
3 min readMay 16, 2020

--

Hope you are able to build custom AOSP emulator as described in the below article :

Now is the time to deploy applications as system apps to this customized or any existing emulator.

Android Emulator Setup to develop System applications

The Develop → Test → Debug cycle for an android system application is quite longer than the normal app development cycle. This article describes the emulator setup and a few handy scripts to facilitate a faster development cycle.

Step 1 — Setting up the emulator

If you are using Android Studio like me, the AVD manager of the android studio comes with plenty of preconfigured AVD options to create a virtual device. But most of them are targeted for general app development. we really need to pay attention while creating a virtual device for system apps development. You are free to select any device configuration that matches your requirement. But while selecting a system image for the virtual device, we need to select an image which DOES NOT include “Google APIs”. This is because, if you use images with “Google APIs” we will not be able to sign our system applications with the same key as Google API since it is not available to us. Whereas the plain AOSP images without Google APIs, we can obtain the platform keys from AOSP repository and we can use it to sign our system applications. The image highlighted in green is the right one for AOSP Oreo 8.1.

In case if you have an emulator with “Google API” and try to sign your system app with AOSP platform keys, be assured that it will NOT work.

Step 2 — The Applications Manifest

If you are intent to run your app as a system process, then it is important to include android:sharedUserId attribute in the AndroidManifest.xml

Once you add this attribute, please note that this application can only be installed as a system app. If you try to install this as a normal app, it will fail.

Step 3 — Writing to System partition of the emulator

In order to make an app as a system app, it needs to be installed in “/system/app/” folder. The system partition of the emulator is read-only and you may not be able to do an adb push directly. To make the system partition writable, we need to restart the emulator with “-writable-system” flag

Once the emulator is restarted in writable system mode, use the following snippet to sign your app with AOSP keys and deploy it to system

The above snippet will install your app as a system app and once the emulator reboots you can see your app installed as a system app.

To uninstall the app, we simply need to remove the Applications folder from “/system/app/”. A sample snippet is shown below

Step 4 — Confirming System app status

How do we verify whether our application is indeed running as a system application?

There are a couple of ways, one is that if you open the “App Info” of the application, there will not be any provision to “Uninstall” it since it is a system application. But the foolproof way is to add a debug log to print the Process’s uid once the application is running. Add this code snippet in your Activity’s code

If your application is running as a system process, then it would print

which means your process’s uid matches to that of Process.SYSTEM_UID. If it matches then congratulations your application is a system application now.

--

--

Raju K
XRPractices

Innovator | XR | AR | VR| Robotics Enthusiast | Thoughtworks