- ApkTool – Decompile and Edit APK (Windows, Mac & Linux)
- Warning
- Set up Requirements
- Download and Set up apktool
- apktool Tutorial to Edit APK Files
- Decompile, Edit and Recompile APK Files
- Compile APK from a Modified Source
- Разборка (декомпиляция) APK файла с помощью Apktool
- Modifying an APK File
- 🧾 Problem
- 💡 Solution
- 🛠 Materials needed
- Don’t have the .apk file?
- 📚 Prerequisites
- Java JRE/JDK
- Apktool
- Apktool Online (optional)
- APK Decompiler (optional)
- 📇 Step-By-Step Guide
- Step 1. Preparing project folder
- Step 2. Decompiling the .apk file
- Decompiling with readable source code
- Step 3. Recompiling the app
- Step 3.1. Creating a key for signing
- Step 3.2. Signing the app
- Step 4. Installing the app
ApkTool – Decompile and Edit APK (Windows, Mac & Linux)
Long back in 2016, we published a detailed tutorial on compiling and decompiling APK files using APK Easy Tool. Today, we’ve come up with another utility that lets you compile and decompile APK files even more easily and it’s simply called ‘apktool’, a Java-based tool that works on Windows, Linux, and MacOS. In this apktool tutorial, we’ll see how to use apktool to compile APK from a modified source, decompile APK, edit and recompile APK files, and make an Android app package.
APK modding is quite common in the Android world. By modding an APK file, you can add or remove features from an App, sign it with your own key, change the UI design or theme the UI and add custom translations. APK modding can also be potentially used to inject malicious code inside an App. This is the reason why special care must be taken when installing modified APKs from third-party sources. In this article, we will discuss the basics of how to manipulate an APK to apply modifications to it.
In order to do any sort of modification to an Android APK file, you must first decompile it, edit its contents and then compile it back. Currently, the easiest way to do this is using a special desktop PC tool known as apktool. Apktool is a Java-based utility which can run on Windows, MacOS, and Linux with minimal effort. Once it is set up, it can decompile or compile an APK file with a single command.
Warning
Modifying APK files might cause them to become unstable and/or unusable. Be extra cautious when manipulating system APK files, as a wrong change might render your device inoperable. DroidViews does not support in any way modifying APK files to add malicious code in them. This process is strictly prohibited by law.
Set up Requirements
Before you can follow our apktool tutorial, there are a few prerequisites you need to take care of. The only requirement of apktool is Java version 1.8 or greater. You can check if you have Java installed on your machine by opening a command prompt on Windows (click the Start Menu, type cmd.exe and hit enter) or a terminal on MacOS/Linux and giving the command
If this command returns 1.8 or greater, you are good to go. If not, you need to install Java first. You can get Java for your machine here.
Download and Set up apktool
You can download the latest version of apktool by clicking on this link. When the download is finished, rename the file to apktool.jar. You will next need to download a wrapper file, depending on your desktop Operating System. You can get the wrapper file by using the following links. For your convenience, right click on the link and select ‘Save As’.
Save the file as apktool.bat on Windows and apktool on MacOS/Linux:
Finally, you will need to move both the apktool and wrapper files to a special location so they can be executed everywhere on the system: On Windows, this location is C:\\Windows . On MacOS and Linux, place them under /usr/bin or /usr/local/bin (root required). If you are on Linux or MacOS, make sure that both files have the execute permission set.
To test that everything works as expected, open a command prompt on Windows or a terminal emulator on MacOS and Linux. Then issue the command apktool and hit enter. You should get an output similar to the following:
apktool Tutorial to Edit APK Files
We will cover only the basics of APK file manipulation. This only includes decompilation and compilation. Anything else lies outside of the scope of this article and should be covered in a separate writing.
Decompile, Edit and Recompile APK Files
First, download the APK file which you need to decompile and edit. In this guide, we will be using the Facebook Lite App APK as an example. You can download it here.
Next, open a terminal emulator or command prompt inside the folder you downloaded the APK file to. To do this on Windows, navigate to the folder using Windows Explorer and then type CMD in the address bar as shown below. Hit enter and a command prompt window will open.
Decompiling an APK file is quite simple. You just need to issue a command in the following form:
For the Facebook Lite App, this will get into:
apktool d facebook_lite_v118.0.0.9.94.apk
Apktool will create a new folder with the same name as the APK file and place all the App data inside it.
The new folder will have a structure similar to the following:
- The res folder contains everything that has to do with translations and user interface layout.
- The smali folder contains App source code in the smali form. Smali is a language type similar to assembly. To make any changes apart from cosmetic ones to an App, these are the files you need to mess with.
- The unknown folder contains everything else that comes packaged inside the APK file but does not follow Google’s guidelines for APK packaging.
- Lastly, AndroidManifest.xml is the Manifest file. This contains information like the App name and characteristics, the Intents it listens to and the Permissions it uses.
Compile APK from a Modified Source
Compiling a modified source with apktool is as simple as decompiling. You can get the job done by just issuing a command in the form:
In our example with the Facebook Lite App, this will get into:
apktool b facebook_lite_v118.0.0.9.94
That is all you need to know if you want to compile and decompile APK files for Android. Stay tuned for special guides about manipulating App icons and colors and adding or removing functionalities to your apps! Try it now and let us know if you were able to decompile and compile an APK. I just hope our apktool tutorial will help you edit APK files yourself.
Разборка (декомпиляция) APK файла с помощью Apktool
Пишем cmd — переходим в командную строку и пишем apktool.
Весь процесс происходит в командной строке.
Но сделать иначе, есть графический интерфейс ApkTool с названием Smartapktool. Скачиваем приложение Smartapktool (ссылка скачать внизу статьи) распаковываем его в папку. Очень важно, чтобы файлы apktool лежали в папке Windows , не путать с Smartapktool. Запускаем интерфейс SmartApkTool.exe и переходим в меню Распаковать/Запаковать. Выбирайте Ваше приложение ~name .apk (Важно! Отсутствие пробелов, кириллицы, знаков препинания).
После распаковки приложения вы обнаружите рядом папку с таким же названием.
Статьи по теме APK:
- Что такое APK?
- Необходимые инструменты для работы с APK
- Как устанавливать приложения для Android с расширением apk
- Как удалить приложения (программы, игры) на android?
- Как скачивать и покупать приложения с Google Play
- Что такое root в Android?
- Структура APK файла
- Разборка (декомпиляция) APK файла с помощью Apktool
- Локализация файла APK
- Упаковка APK приложения и подпись (компиляция и подпись)
- Выбор места установки приложения APK
- Редактирование и замена иконок в APK
- Узнаем какие права у приложения APK
- Как извлечь установочный файл с приложением (.apk) из системы
- Как удалить рекламу из приложений APK
- Как скачать приложение APK на компьютер с Google Play
- Какие встроенные (системные) приложения Android можно удалить
- Деодексирование системных приложений в Андроид
- Как редактировать системные apk
- Как получить исходный код приложения с расширением Apk
- Одексирование Android приложений
Modifying an APK File
Decompiling and recompiling an APK can be easily done using Apktool.
🧾 Problem
You have an .apk file that you want to view/edit these following contents:
- Resources such as strings.xml or other drawables
- App configurations such as AndroidManifest.xml
- Source codes such as Java classes
This post is not intended for piracy and other non-legal uses. This post could be used for localizing, adding features, supporting custom platforms, analyzing applications.
💡 Solution
🛠 Materials needed
.apk file that you want to decompile.
Don’t have the .apk file?
If the app is listed on the Google Play Store, you can use websites such as apkpure.com, apkmirror.com.
If it’s not listed but installed on your Android device, you can use APK extracting apps such as Apk Extractor to get the .apk file for the app.
Warning: APK decompiliation using Apktool might not work properly for apps encrypted with ProGuard or other methods.
📚 Prerequisites
You would need basic knowledge of using the Android SDK and how an Android app is built.
Java JRE/JDK
At least Java 1.8 should be installed to use Apktool. If you intend to rebuild the app, you would need JDK to use the command keytool and jarsigner .
To check your Java version, run java -version on command prompt. To install Java, click here.
Apktool
Click here to learn how to install Apktool for Windows, Linux and macOS.
If you want to use the command apktool globally, you can install Apktool on C:/Windows . But if you plan to only use it for a short time, you can install Apktool on your project folder to only use it in the folder.
Apktool Online (optional)
If you only intend to decompile the app without rebuilding the app to the .apk format, you can use Apktool online without installing Apktool on your computer.
If you intend to build the app with the changes you made, you need to install Apktool.
APK Decompiler (optional)
If you intend to analyze the source codes such as Java classes, you need to use dex2jar compiler. You can use it online from here.
Tip: I recommend using both Apktool and APK decompiler in order to trace which resource is used where and how.
📇 Step-By-Step Guide
Step 1. Preparing project folder
Put your .apk file in a project folder of your choice. In this tutorial, the project folder is named as \proj .
Your project folder would look like this:
proj +-- app.apk // the app to decompile +-- apktool.bat +-- apktool.jar
In this tutorial, I installed the Apktool locally in the project folder. Therefore apktool.bat and apktool.jar exists in the same folder.
Step 2. Decompiling the .apk file
Decompile app.apk using Apktool.
In this tutorial, I used Windows PowerShell for command prompt.
After execution, you will see the \app folder created by Apktool. In the folder, you can see all the resources such as AndroidManifest.xml and the resource directory \res and its contents in original form.
If you want to edit AndroidManifest.xml or the resource, you can edit and overwrite to the original file.
Decompiling with readable source code
Source code is decompiled to .smali files, making it unreadable. So if you want to read the source code, you have to use the APK Decompiler using dex2jar compiler.
Open APK Decompiler on your browser, and choose your .apk file with the Choose File option. Decompile the file by clicking on Upload and Decompile button.
After the processing is done, download the results by clicking on Save button. Download the .zip file to the project folder and unzip it.
Step 3. Recompiling the app
Recompile \app into app.apk using Apktool.
The built APK would be located in \app\dist . The changes you made in the \app folder is applied to the new APK file.
Step 3.1. Creating a key for signing
To install the edited APK to an Android device, you need to sign it with a signature key. Create a key using keytool , a tool provided as a part of JDK.
keytool -genkey -v -keystore release.keystore -alias alias_name -keyalg RSA -keysize 2048 -validity 10000
Enter password, name, organization information, address for the new keystore. This will generate release.keystore , and this will be used to sign your new app.
The password will be used as a passphrase to sign the app.
Step 3.2. Signing the app
Sign the APK with the generated key using jarsigner , a tool provided as a part of JDK.
jarsigner -verbose -sigalg SHA1withRSA -digestalg SHA1 -keystore release.keystore app/dist/app.apk alias_name
Enter the passphrase for your keystore. This will sign and update the apk file \app\dist\app.apk .
Step 4. Installing the app
Locate and install the apk file \app\dist\app.apk to your device of choice.
If you don’t see changes after installing the app, double check whether you installed the updated version in \dist , not the original APK file.
Updated: May 1, 2021