[GUIDE][HOW-TO] Decompile and Compile apps using Apktool in 5 Simple Steps

Search This thread

sekthesamurai

New member
Sep 8, 2019
2
0
Hello. I follow all steps and i signed apk. after that i setup the app in my phone(not rooted) and when i start the app (galaxy wearable - modified for 1.5 gb ram phone) is says “The operating system on your phone has been modified in an unauthorized way, and is not compatible with the Galaxy Wearable app. Check your operating system and try again.” in this situation what can i do. looking forward for your help.thanks.
 

nelsonkim2019

New member
Nov 23, 2019
3
1
Device cannot reboot after changing settings.apk

Hi, I follow the exact steps in this guide, using zipsigner-platform to sign the apk, and load it. Everything works fine, until I restart the device. Then it stuck in the logo screen when booting. Initially I thought the change trigger knox or validity check, so I managed to suppress the knox, and load a no-validity-xxxx.zip. But still it stuck. And while it stuck, it use adb shell back into the screen (this is a rooted phone with twrp), and change back the settings.apk (basically put back the original settings), it goes on to reboot fine ...

Finally I find some hint when looking through the logcat logs, the device is stuck when keeps trying on this:
W/Atfwd_Sendcmd: AtCmdFwd service not published, waiting... retryCnt : 1
----and this retry goes on to retryCnt : 5 and then a few other things, and restart.

This is on Samsung GP Pro, SM-J250f, rooted phone, with twrp installed.

Please help, I tried many things (an old mobile developer, way back from blackberry years in 2004, through Nokia, Windows Mobile, iPhone, and Android 2,3,4,5 till Q now), and I am a little out of ideas. Please help!
 
  • Like
Reactions: allcius

asimrasheed

New member
Jun 29, 2022
1
1
Hello :)

I want to keep things simple and very easy. I will write a 5 step guide for setting up apktool and start modifying your app's or any other android framework. This guide will be strictly for windows users, since setting up and using apktool in windows is the easiest.
So lets begin -


What you need before you learn how to use apktool -


  1. A computer running windows
  2. A working internet connection for downloading the following -
    • JAVA SDK and JRE
    • Android SDK
    • Apktool core tool
    • Sign apk tool
  3. Basic command prompt commands and path knowledge
  4. A good linux format code editing program like NotePad ++ [Get it from HERE]


STEP 1 - Install JAVA - Go HERE

attachment.php


  • Just go to the above website and download java SDK and JRE.
  • We mostly use only SDK libraries but JRE is required when you want to modify games or apps like whatsapp. So its best if we install both.
  • install them in any directory for example C:\ drive and you are good to go to next step 2.

STEP 2 - Install Android SDK- Go HERE

attachment.php


  • Just go to the above website and download the SDK.
  • Install it in an easy path. For example - C:\android
  • The short path will be useful when you are using adb for logcat purposes, since typing in a long path every-time you want to access the adb executable file is painful.
  • So once you installed the SDK move on to next step 3

STEP 3 - Download Apktool - Go HERE

attachment.php


  • For downloading apktool related files, you need to go HERE
  • Download latest apktool version, currenlty 1.5.2
  • Download the batch file and aapt.exe
  • Create a folder anywhere in the pc and put all the apktool.jar, aapt.exe and the batch script in that folder. [see screenshot]
  • This will be the operating folder for you now.
  • Next move to next step 4

STEP 4 - Using apktool for decompiling anything

attachment.php


  • Open command prompt
  • navigate to the folder where you placed apktool.jar, batch script and the aapt.exe [see screenshot]
  • For this guide i am using a simple framework-res.apk for reference.
  • Once you are in the folder via cmd prompt, you need to install the file using the " IF " command
  • type the following command -

    Code:
    [B]apktool if [I]name-of-the-app[/I] .apk[/B]

    For example, once the command is executed correctly, it will look like this -
    attachment.php

    Code:
    [B]apktool if framework-res.apk[/B]
  • Once the app is installed you need to decompile it.
  • For decompiling use the command "d". The "d" stands for decompile.

    Code:
    [B]apktool d [I]name-of-the-app[/I] .apk[/B]

    For example -

    Code:
    [B]apktool d [I]framework-res.apk[/I][/B]
  • After the app is correctly decompiled, a new folder will be created in the same folder where you placed your app. This contains all the xml's and smali files which can be edited for different mod's.

    For example, here's how it will look once the app is decompiled -
    attachment.php
  • Then after you are finished with your modding, you need to recompile your app for using it.
  • To recompile the app use the following command " B ". The "b" simply means recompile.

    Code:
    [B]apktool b [I]name-of-the-app-folder[/I][/B]
  • NOTE - While recompiling the app, you just need to type the name of the folder the app's files contains.
    For example -

    Code:
    [B]apktool b [I]framework-res[/I][/B]

    framework-res is the name of the folder
  • The final modded app will be in the dist folder located inside the original app folder created by apktool.

    For example -
    attachment.php
  • Congrats ! If everything went well, you successfully created a modified app ! :)
  • Now the most important step is below in step 5





STEP 5 - Signing the apk

  • to sign an apk download the "sign-apk.rar" from below attachements
  • extract it to any place.
  • open a new command prompt and change into the sign-apk directory using cmd
  • move the modified-unsigned apk into this folder [see screenshot] -
    attachment.php
  • then type the following command -

    Code:
    [B]java -jar signapk.jar certificate.pem key.pk8 [I]path-of-the-folder-contaning-the-apk .apk path-of-the-new-signed-apk .apk[/I][/B]

    For example -
    attachment.php


    Code:
    [B]java -jar signapk.jar certificate.pem key.pk8 [I]framework-res.apk framework-res-signed.apk[/I][/B]
  • Once compiled, the signed apk will be found in the same folder.
    attachment.php
  • This is FINAL APK. :)
  • Simply rename it to the original apk and push it into the system ! DONE ! :D


If you have any errors or problems related to apktool, post them here, I will try to solve them. :)
Dear
Thanks for your description about editing apk files. I tried this method and everything worked fine except last step of signing modified apk as it gives error:
Exception in thread "main" java.lang.NoClassDefFoundError: sun/misc/BASE64Encoder
at com.android.signapk.SignApk.addDigestsToManifest(SignApk.java:169)
at com.android.signapk.SignApk.main(SignApk.java:325)
Caused by: java.lang.ClassNotFoundException: sun.misc.BASE64Encoder
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:606)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:168)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
... 2 more

I will highly appreciate if you can spare some time and guide me to resolve the issue.
Kind Regards
Asim
signalian@yahoo.com
 
  • Like
Reactions: mrfatiga22

Top Liked Posts

  • There are no posts matching your filters.
  • 172
    Hello :)

    I want to keep things simple and very easy. I will write a 5 step guide for setting up apktool and start modifying your app's or any other android framework. This guide will be strictly for windows users, since setting up and using apktool in windows is the easiest.
    So lets begin -



    What you need before you learn how to use apktool -

    1. A computer running windows
    2. A working internet connection for downloading the following -
      • JAVA SDK and JRE
      • Android SDK
      • Apktool core tool
      • Sign apk tool
    3. Basic command prompt commands and path knowledge
    4. A good linux format code editing program like NotePad ++ [Get it from HERE]


    STEP 1 - Install JAVA - Go HERE

    attachment.php


    • Just go to the above website and download java SDK and JRE.
    • We mostly use only SDK libraries but JRE is required when you want to modify games or apps like whatsapp. So its best if we install both.
    • install them in any directory for example C:\ drive and you are good to go to next step 2.

    STEP 2 - Install Android SDK- Go HERE

    attachment.php


    • Just go to the above website and download the SDK.
    • Install it in an easy path. For example - C:\android
    • The short path will be useful when you are using adb for logcat purposes, since typing in a long path every-time you want to access the adb executable file is painful.
    • So once you installed the SDK move on to next step 3

    STEP 3 - Download Apktool - Go HERE

    attachment.php


    • For downloading apktool related files, you need to go HERE
    • Download latest apktool version, currenlty 1.5.2
    • Download the batch file and aapt.exe
    • Create a folder anywhere in the pc and put all the apktool.jar, aapt.exe and the batch script in that folder. [see screenshot]
    • This will be the operating folder for you now.
    • Next move to next step 4

    STEP 4 - Using apktool for decompiling anything

    attachment.php


    • Open command prompt
    • navigate to the folder where you placed apktool.jar, batch script and the aapt.exe [see screenshot]
    • For this guide i am using a simple framework-res.apk for reference.
    • Once you are in the folder via cmd prompt, you need to install the file using the " IF " command
    • type the following command -

      Code:
      [B]apktool if [I]name-of-the-app[/I] .apk[/B]

      For example, once the command is executed correctly, it will look like this -
      attachment.php

      Code:
      [B]apktool if framework-res.apk[/B]
    • Once the app is installed you need to decompile it.
    • For decompiling use the command "d". The "d" stands for decompile.

      Code:
      [B]apktool d [I]name-of-the-app[/I] .apk[/B]

      For example -

      Code:
      [B]apktool d [I]framework-res.apk[/I][/B]
    • After the app is correctly decompiled, a new folder will be created in the same folder where you placed your app. This contains all the xml's and smali files which can be edited for different mod's.

      For example, here's how it will look once the app is decompiled -
      attachment.php

    • Then after you are finished with your modding, you need to recompile your app for using it.
    • To recompile the app use the following command " B ". The "b" simply means recompile.

      Code:
      [B]apktool b [I]name-of-the-app-folder[/I][/B]
    • NOTE - While recompiling the app, you just need to type the name of the folder the app's files contains.
      For example -

      Code:
      [B]apktool b [I]framework-res[/I][/B]

      framework-res is the name of the folder

    • The final modded app will be in the dist folder located inside the original app folder created by apktool.

      For example -
      attachment.php

    • Congrats ! If everything went well, you successfully created a modified app ! :)
    • Now the most important step is below in step 5


    NOTE - You MUST follow the step 5. Or else the app wont work and when you try to push it into system, the rom will be stuck in bootloop XD


    STEP 5 - Signing the apk

    • to sign an apk download the "sign-apk.rar" from below attachements
    • extract it to any place.
    • open a new command prompt and change into the sign-apk directory using cmd
    • move the modified-unsigned apk into this folder [see screenshot] -
      attachment.php
    • then type the following command -

      Code:
      [B]java -jar signapk.jar certificate.pem key.pk8 [I]path-of-the-folder-contaning-the-apk .apk path-of-the-new-signed-apk .apk[/I][/B]

      For example -
      attachment.php


      Code:
      [B]java -jar signapk.jar certificate.pem key.pk8 [I]framework-res.apk framework-res-signed.apk[/I][/B]
    • Once compiled, the signed apk will be found in the same folder.
      attachment.php
    • This is FINAL APK. :)
    • Simply rename it to the original apk and push it into the system ! DONE ! :D


    If you have any errors or problems related to apktool, post them here, I will try to solve them. :)
    16
    apple.jpg


    STEP 1 : Rooting MAC

    If you have a mac, apk manager doesn't work on macs. So, you must use apktool. To set up apktool, you must have root mode enabled on your mac. To do that, simply follow these steps:
    • Open system preferences
    • Open accounts
    • Go to login options
    • Hit join next to network account server
    • Select open directory utility
    • Click the lock at the bottom of the window that pops up and enter an admin password
    • Then, go to the top bar on your mac, hit edit, and select enable root mode


    STEP 2 : SETTING UP APKTOOL

    Once you have root mode enabled, you're ready to set up apktool :
    • From the apktool website, download apktool-latest-version.tar.bz2 and apktool-install-macosx-latest-version.tar.bz2
    • Next, open terminal type :

      Code:
      [B]su
      tar -C /usr/local/bin -xvf <zipped file name>
      tar -C /usr/local/bin -xvf <zipped file name> (for the second file)[/B]
    • Now to confirm it worked, type "apktool" no quotes
    • You should get a help menu for apktool
    • If you got it, you're good to go to next step.


    STEP 3 : USING APKTOOL

    Now, once you have it set up, you're ready to go! After typing apktool, you'll see the help menu which'll give you the commands available for apktool, but I'll go over the basic ones here.
    • For installing frameworks or apps
      Code:
      apktool if
    • This command will decompile the apk
      Code:
      apktool d "apk path here"
    • This command will build an apk from a previously decompiled one
      Code:
      apktool b "decompiled apk path here"

    ----------------------------------------------------------

    linux_logo.jpg


    Screenshot%20from%202012-08-19%2022:04:45.png


    Download the apktool.java file along with other files, as shown above. Extract them to the desktop.

    Now open terminal and type line by line :

    Note : "android" in all the below commands is my username. So it changes according to your pc name ;)

    We are giving root permissions for the 3 files that you extracted above.
    Code:
    chown -R android:android '/home/android/Desktop/apktool.jar'
    press enter

    Code:
    chown -R android:android '/home/android/Desktop/aapt'
    press enter

    Code:
    chown -R android:android '/home/android/Desktop/apktool'
    press enter


    Next make all 3 files executable by doing the same thing one at a time pressing enter in between each one:
    Code:
    sudo chmod +x '/home/android/Desktop/apktool.jar'
    after the first it will ask you for your password type it, you shouldnt need it after that for the rest

    Code:
    sudo chmod +x '/home/android/Desktop/aapt'
    Code:
    sudo chmod +x '/home/android/Desktop/apktool'
    now we need to move all three files to bin folder to do it type this command and enter your password:
    Code:
    gksudo nautilus
    a new window should pop up on the left click on "filesystem/usr/local/bin, then drag all three folders into the bin folder and close it.

    APKTOOL is now ready and make your modifications on a linux distro easily :)
    4
    noob question...
    pls tell me where to put baksmali.jar, smali.jar, baksmali.file, smali.file ?
    and how to use
    thanx

    Okay, first thing first, you'll need all of the above mention file, the appt.exe
    & apktool.bat is in a bz2 file [like zip] download it from the apktool website
    here http://ibotpeaches.github.io/Apktool/ & scroll down, you'll see below
    NEWS [23 Dec 2012 - Scripts r05-ibot Released] download it depending on
    your PC Windows,Mac, etc. & extract. Then download the latest apktool that
    is apktool 2.0 here https://bitbucket.org/iBotPeaches/apktool/downloads &
    rename it to [apktool.jar] After that, download all baksmali & smali V2.03
    here https://code.google.com/p/smali/downloads/list [I know baksmali &
    smali has been updated, but V2.0.3 is working flawlessly] Lastly, put all of the files
    into any folder you want or I would recommend to create a new folder named
    [apktool] in C:/Windows/HERE [apktool] after that run it by the apktool.bat
    or press [Shift + Right Click] then you'll see option "open command window here"
    Then check your current version by typing in CMD
    Code:
    apktool -version
    If it show " apktool 2.0.0" in CMD, then you've successfully installed :good:
    To use it for compiling, first put framework-res of your ROM in the apktool folder
    I've mention, then put any apk you want to compile [example, SystemUI.apk]
    First, to prepare the compiling type in CMD
    Code:
    apktool if framework-res.apk
    Then, type
    Code:
    apktool if SystemUI.apk
    After that, type
    Code:
    apktool d SystemUI.apk
    Lastly, after done editing & stuff, recompile by typing in CMD
    Code:
    apktool b SystemUI
    [for recompiling, you do not need to type the ".apk" at the end of apk name, just
    simply type the apk name]
    NOTE: You don't have to do the, "apktool if SystemUI.apk" command for other APK
    Just do the "apktool if framework-res.apk" at the beginning & you're good to go :cowboy:
    Hit the thanks button if I helped :fingers-crossed:
    2
    will write that first thing tomo morning...but why not dual boot windows ? can that be done in mac ? i dont know since i never used mac...

    Yeah it can but my father... but I can with parallels app without him discover I just need found one cracked :x

    Sent from my GT-S5570 using xda app-developers app