How to use BatchApkTool to decompile and recompile MIUI system apps
In this tutorial, we’ll learn the basic usage of BatchApkTool for decompiling, modifying and recompiling.
BatchApkTool is powerful tool consisting of multiple features for modifying not only android apks, but also jar files. BatchApkTool is available only in Windows.
For Linux system users, ShimApkTool is recommended. Tutorial for Shik Apktool will be posted soon.
This tutorial is applicable in decompiling, modifying and recompiling other apps in other ROMs as well
Prerequisites
- BatchApkTool – Link Here
- Notepad++
- Unpacked ROM (with folders like app, priv-app, framework,…)
Step 1) : Extract and configure BatchApkTool
- Extract BatchApkTool to your working folder
- Open BatchApkTool.exe
- Select language of your choice ( 3 = english )
- Set API Level (30 for Android 11 , 29 for Android 10)
- Turn on Expert mode
- Turn off “Sign output apks“
Step 2) : Finding the framework apps before decompiling the target APK
- Inorder to unpack and modify our target APK without error, a few other APKS called “framework apks” are needed. These apps are specific to the ROMs that you use. Examples are given below.
- The necessary framework apps has to be copied to _framework folder inside BatchApkTool folder.
- The easiest method to find the framework apks is to use the FindFramework plugin in BatchApkTool :
- Copy the system folder (containing app, framework, priv-app, product, system_ext) to _system folder of BatchApkTool
- Open plugins in BatchApkTool (No. 7 under the APKTOOL section) and select FindFramework plugin (No. 3)
Now the tool will automatically find the necessary files required to decompile and recompile the target APK and copy them to _framework folder of BatchApkTool
-
In MIUI 12.5 Android 11, the framework apks are :
-
-
- framework-res.apk
- framework-ext-res.apk
- GoogleExtShared.apk
- miui.apk
- miuisystem.apk
- RtMiCloudSDK.apk
-
-
- The easiest method to find the framework apks is to use the FindFramework plugin in BatchApkTool :
Now that we have obtained the necessary framework files inside the _framework folder, copy the target APK to the _INPUT_APK folder of BatchApkTool
In this tutorial, I will use the Settings.apk from MIUI 12.5 as the Target APK. You can use any APK you wish to modify
You can decompile a target APK in 3 methods :
-
-
- Only resources – unpacks everything including resources.arsc and excludes dex files
- Only smali – only unpacks dex files (classes.dex)
- Both resources and smali
NB: Decompiling smali only doesn’t require the use of framework APKS inside _framework folder.
After decompilation, the Target APK will be seen extracted inside the _INPUT_APK folder inside the BatchApkTool folder.
Eg : BatchApkTool\_INPUT_APK\Settings
-
-
Step 4) : Modifying the Target APK
Now, Make the necessary modifications you want to change inside the extracted Target APK
Let’s change a string inside the folder res\values\strings.xml.
Notepad ++ is best recommended for editing the xml files
After making the changes, save it.
Step 5): Recompiling the APK and getting output
Open BatchApkTool.exe
Go to APKTOOL section. Recompiling has to be done according to the decompilation method you used.
Output APK will be obtained inside _OUT_APK folder inside BatchApkTool folder, after successful decompilation.
Error might occur while recompiling.
A log file will be formed inside the BatchApkTool root folder. Read the log file to understand the error and rectify it.
Thank you for the guide. It would be also helpful if it would have a video tutorial and Link for the tool. 🙂