How to Decompile, Modify, and Rebuild an APK File

If you’re interested in modifying Android APK files—whether to explore their inner workings or customize them for personal use—this guide will take you through the essential tools and steps needed to decompile, make changes, and recompile APKs. Below, we’ll cover the main tools involved in this process and give you step-by-step instructions.

Tools You’ll Need

  1. apktool: A tool for reverse engineering APK files. It’s used to extract and rebuild the APK after making changes.
  2. keytool: A Java tool for generating keys and certificates, included with the JDK.
  3. jarsigner: A Java tool for signing JAR and APK files, also included with the JDK.
  4. zipalign: An archive alignment tool from the Android SDK for optimizing APK files.
  5. JD-GUI: A graphical utility for viewing Java source code.
  6. dex2jar: Converts Android DEX files into Java class files.

Step-by-Step Instructions

Step 1: Decompile the APK

The first step in modifying an APK is to decompile it to access the resources, code, and assets. Use the apktool to decompile the APK.

Run the following command in your terminal:

apktool d -r -s application.apk

Alternatively, if you don’t need the resources and only want the code, you can use:

apktool d application.apk

This will create a folder named application, which contains the assets, resources, and compiled code of the APK.

Step 2: Convert DEX Files to Java Class Files (Optional)

If you want to inspect or modify the Java code, you can convert the DEX (Dalvik Executable) files to standard Java class files. Skip this part if you only want to edit resources or the manifest.

  1. Convert the DEX files to JAR files using dex2jar: dex2jar application/classes.dex
  2. Use JD-GUI to inspect the generated JAR file: jd-gui classes-dex2jar.jar

You can now view the Java code, make any necessary changes, or simply inspect it for your own knowledge.

Step 3: Modify the APK (Optional)

You can now make changes to the APK. For example:

  • Change the orientation of the main activity in the AndroidManifest.xml file.
  • Modify strings or other resources in strings.xml or the res folder.

Make the desired modifications before proceeding to the next step.

Step 4: Rebuild the APK

After making your changes, you need to recompile (rebuild) the APK using apktool.

Run the following command:

apktool b -f -d application

This will generate the modified APK in the Dist folder. The newly compiled APK will be named application.apk.

Step 5: Sign the APK

Before installing the APK on your device, you need to sign it to ensure its authenticity. If you don’t already have a key, you can generate one using keytool.

  1. Create a key using the following command: keytool -genkey -v -keystore my-release-key.keystore -alias alias_name \ -keyalg RSA -keysize 2048 -validity 10000 You’ll be prompted to set a password for the keystore.
  2. Sign the APK using jarsigner: jarsigner -verbose -sigalg SHA256withRSA -digestalg SHA-256 -keystore my-release-key.keystore my_application.apk alias_name
  3. To verify the APK, use this command:bashCopy codejarsigner -verify -verbose -certs my_application.apk

Step 6: Align the APK

For optimal performance when loading the APK on an Android device, you should align it using zipalign.

Run the following command:

zipalign -v 4 my_application.apk my_application-aligned.apk

This will create the aligned APK, named my_application-aligned.apk.

Note: If you use apksigner, the alignment must be done before signing. The recommended method is to use apksigner, not jarsigner.

Step 7: Install the APK

Now that you have the modified and signed APK, you can install it onto your Android device.

Final Thoughts

By following these steps, you can easily decompile, modify, and recompile an APK file to suit your needs. Whether you want to inspect the Java code, change resources, or just tweak settings, this process provides a comprehensive approach to working with Android APKs.

If you’re working on a project that requires in-depth APK modifications, these tools and steps will be indispensable. Happy decompiling!

Workaround: Trouble Viewing PDF Attachments in iOS 7.1 with Exchange Account

Got a call that there was a problem viewing emails with attached PDFs today. PDFs were getting mangled up when viewing them on the iPhone (iOS 7.1 and 7.1.1). Did some general testing on the MS Exchange server (2003, btw) and disabled A/V, Firewall and some other things to make sure it wasn’t causing the problem. Outlook and OWA were able to open the PDF without issue so it was targeted at iOS devices it seemed.
The environment for which I took the helpdesk call consists of:

  • Microsoft Exchange 2003 Standard (fully patched)
  • Symantec Endpoint Small Business (fully updated)
  • Windows Server 2003 R2 (fully updated)
  • Mixture of iPhones (various iOS levels)

Discovered through an Apple Community Post that there was a bug in iOS (at least we are pointing fingers at iOS anyway).

Workaround

To work around this problem of opening the PDF, take a look at the screenshot below. Download Full Message then download/open the attached PDF.
photo2
Hope this helps anyone else out there.

How to Manage iPhones in Enterprise Environments

Apple has a few tools to help aid in managing iPhones in the enterprise environment.  From configuring VPN profiles, eMail accounts, wireless network configurations and ActiveSync.
You can download the iPCU (iPhone Configuration Utility) from Apple’s website:  http://www.apple.com/support/iphone/enterprise/

Enterprise

  • iOS Enterprise Deployment Resources

    How to integrate iOS devices with your enterprise systems, including mail, calendaring and VPN. How to create and distribute custom configuration profiles and applications.
  • iPhone Support Communities – Enterprise

    Discuss this topic with fellow iPhone users.

Apple Configurator

  • Apple Configurator Help

    Apple Configurator for OS X Lion makes it easy for anyone to deploy iPhone, iPad and iPod touch in their school or business. Apple Configurator can be used to quickly configure large numbers of iOS devices with the settings, apps and data you specify for your students, employees or customers.
  • Apple Configurator: Backing up and restoring data

    You can use Time Machine or any other backup strategy to back up and restore Apple Configurator data including device configurations, users, apps, documents, iOS versions, and VPP redemption codes.
  • Using Volume Purchase Program (VPP) Redemption Codes

    Learn how to use Apple Configurator to deploy copies of paid apps using redemption codes purchased from the Volume Purchase Program (VPP).
  • Using Apple Configurator to enroll devices in Profile Manager

    Learn how to import Enrollment Profiles created in Profile Manager into Apple Configurator, then install the profiles onto devices.
  • Preserving user-installed apps when updating settings on an assigned device

    Learn how to preserve apps installed by a user who has checked out a device that is supervised by Apple Configurator.
  • Coordinating device names with labels or slot numbers in carts and racks

    You can use Apple Configurator to assign device names that correspond to a label on the device, or to the slot numbers in a charging cart or rack.

Continue reading How to Manage iPhones in Enterprise Environments