How to run system applications through the emulator in Android studio

This article teaches you how to use the emulator that comes with Android studio to run a system app. Because sometimes the applications you write need to be used as system apps to achieve certain functions, so they need to be set as system apps.

1. Create an emulator

If you want the app to be pushed to the system/app directory of the simulator normally, first make sure that your simulator does not come with Google APIs, and you need to open AVDmanager. Look at the picture below:

 Because this kind of system with Google APIs uses different system signatures than the system signatures generated by the platform.pk8 and platform.x509.pem files you find on the Android open source platform. How to solve this problem can be done when creating the emulator. Select x86 images. Some of the simulators in this option do not have Google APIs.

 This has created an emulator that can install system applications. The next step is how to push the apk to system/app.

2. Start the emulator in root mode

The startup method also needs to be modified. You cannot directly click to start in Android studio. You need to start through a command. You need to start the cmd input in the SDK file android-sdk/emulator directory: emulator.exe -avd Pixel_3a_9.0 (emulator name) - writable-system

 3. How to generate system signature

It’s not over yet. If you want the applications pushed to system/app to be installed normally, you still need to perform system signing.

Get platform.pk8 and platform.x509.pem from the system source code, put them in the same directory as SignApk.jar, and then sign them

Here is a good Android system source code address recommended to you: http://aospxref.com/ The source code inside can not only be viewed, but also downloaded. The platform.pk8 and platform.x509.pem files are in /build/target/product/ under the security/ directory

 Note, you can find it according to your Android version. I am taking 9.0 as an example, and then download these two files. The D of HAD is download. The jar package signapk.jar can be found online.

Start cmd in this folder directory and input: java -Xmx2048m -jar signapk.jar -w platform.x509.pem platform.pk8 original apk address/name signed apk address/name

 The apk generated in this way can be pushed to the system/app of the simulator, and then restarted with adb reboot. After restarting, check whether there is an apk application icon in the simulator. If not, restart it again to see. Sometimes you may need to restart it twice. to install successfully

 Note : After starting the simulator, start cmd through win+R. cmd can be directly associated with the simulator. You can try it through adb root, adb shell and other commands. If the entered command does not respond, then it is a system variable configuration problem. You can refer to the following configuration

Configuration in path

It’s completed. If you have any questions, please leave a message in the comment area.

Guess you like

Origin blog.csdn.net/u012598200/article/details/131450412