Skip to content

Apktool

16 commands

Decodes Android APKs to near-original resources and smali code, and rebuilds them after modification.

  • Android
  • reverse engineering
  • APK

Install Apktool

sudo apt install apktool

Decoding6

apktool d <apk>

Decodes resources and AndroidManifest.xml to readable XML and the code to smali, in a folder named after the APK.

Link
apktool d <apk> -o <dir>

Chooses the output directory.

Link
apktool d -f <apk>

Overwrites an existing output directory.

apktool d -s <apk>

Keeps classes.dex undecoded — faster when you only need resources and the manifest.

apktool d -r <apk>

Leaves resources undecoded, which avoids rebuild problems when you only edit smali.

Link
apktool d --only-main-classes <apk>

Skips extra dex files that are not part of the main app code.

Link

Reviewing3

grep -E "debuggable|allowBackup|exported|usesCleartextTraffic" <dir>/AndroidManifest.xml

Quick manifest review for risky flags and exported components.

Link
grep -rniE "api[_-]?key|secret|password|token" <dir>/res

Hunts for hard-coded secrets in resources.

Link
cat <dir>/res/xml/network_security_config.xml

Shows certificate pinning and cleartext rules.

Link

Rebuilding5

apktool b <dir>

Rebuilds the APK into <dir>/dist/.

Link
apktool b <dir> -o <apk>

Rebuilds to a chosen file name.

Link
zipalign -p -f 4 <in> <out>

Aligns the APK, required before signing with apksigner.

Link
apksigner sign --ks <keystore> <apk>

Signs the rebuilt APK so it can be installed.

Link
keytool -genkey -v -keystore <file> -alias <alias> -keyalg RSA -keysize 2048 -validity 10000

Creates a throwaway signing key.

Link

Frameworks2

apktool if <framework-res.apk>

Installs a vendor framework needed to decode some system apps.

Link
apktool empty-framework-dir --force

Clears cached frameworks when decoding fails with resource errors.

Link