How to Rebuild and Sign an APK Using the reverse-skill Framework

The reverse-skill repository provides a complete PowerShell-based workflow for rebuilding and signing APKs via the rebuild-sign-install.ps1 script, which automates apktool build, zipalign, apksigner, and optional adb deployment.

The reverse-skill framework by zhaoxuya520 is a cross-platform toolkit for Android reverse engineering. Whether you've modified smali code, patched resources, or injected Frida hooks, you need a reliable way to repackage your changes into a valid, installable APK. This article explains how to rebuild and sign an APK using the official tools and scripts provided in the repository.

Prerequisites and Tool Discovery

The rebuild workflow depends on four core command-line tools: apktool, zipalign, apksigner, and adb. The framework handles tool discovery automatically through two mechanisms:

  • Get-Command queries your system PATH first
  • Get-ToolPath falls back to the tool-index.md registry at skills/tool-index.md
  • Auto-bootstrap triggers skills/scripts/bootstrap-reverse.ps1 if any tool is missing

This design ensures reproducible builds across Windows PowerShell, Linux, and macOS (via PowerShell Core). You do not need to manually configure tool paths unless you want to override the defaults.

The rebuild-sign-install.ps1 Script

The core automation lives in skills/apk-reverse/scripts/rebuild-sign-install.ps1. This single script orchestrates the entire pipeline:

Stage Command Executed Output Artifact
Build apktool b <project_dir> <basename>-unsigned.apk
Align zipalign -p -v 4 <unsigned> <aligned> <basename>-aligned.apk
Sign apksigner sign --ks <keystore> <aligned> <basename>-signed.apk
Verify apksigner verify --print-certs <signed> Console verification
Install (optional) adb [-s <serial>] install -r <signed> Device deployment

The script also manages debug keystore generation. If ~/.android/debug.keystore does not exist, it invokes keytool to create a 27-year-valid debug certificate automatically.

Required Parameters and Options

The script accepts several parameters to control the build process:

  • -ProjectDir (required): Path to the apktool output directory containing AndroidManifest.xml and smali folders
  • -OutDir (optional): Custom output directory for artifacts (defaults to project directory)
  • -BaseName (optional): Prefix for generated APK files (defaults to project directory name)
  • -Clean (switch): Removes previous build artifacts before starting
  • -Install (switch): Triggers adb install after signing
  • -Reinstall (switch): Adds -r flag for force reinstall
  • -DeviceSerial (optional): Targets a specific device by serial or IP:port

Basic Rebuild and Sign Example

Start with an apktool project directory (created via apktool d app.apk -o apktool_out). Then run:

pwsh -File "skills/apk-reverse/scripts/rebuild-sign-install.ps1" `
    -ProjectDir "apktool_out" `
    -Clean

Expected output:


unsigned_apk=C:\work\apktool_out\apktool_out-unsigned.apk
aligned_apk=C:\work\apktool_out\apktool_out-aligned.apk
signed_apk=C:\work\apktool_out\apktool_out-signed.apk
keystore=C:\Users\<user>\.android\debug.keystore

The script returns absolute paths for all artifacts, making them easy to reference in downstream automation.

Rebuild, Sign, and Install to Device

Combine the -Install and -Reinstall switches to deploy immediately after signing:

pwsh -File "skills/apk-reverse/scripts/rebuild-sign-install.ps1" `
    -ProjectDir "apktool_out" `
    -Install -Reinstall `
    -DeviceSerial "127.0.0.1:7555"

This executes the full pipeline and finishes with:

adb -s 127.0.0.1:7555 install -r apktool_out-signed.apk

Custom Output Paths

Redirect artifacts to a separate build directory with -OutDir and -BaseName:

pwsh -File "skills/apk-reverse/scripts/rebuild-sign-install.ps1" `
    -ProjectDir "apktool_out" `
    -OutDir "C:\tmp\apk_build" `
    -BaseName "mypatched" `
    -Clean

Generated files:


C:\tmp\apk_build\mypatched-unsigned.apk
C:\tmp\apk_build\mypatched-aligned.apk
C:\tmp\apk_build\mypatched-signed.apk

Complete Workflow: Decode to Deploy

For a full reverse-engineering cycle, chain the decode and rebuild scripts:


# Step 1: Decode APK to smali and resources

pwsh -File "skills/apk-reverse/scripts/decode.ps1" `
    -ApkPath "app.apk" `
    -Clean

# Step 2: Modify smali or resources manually

# Step 3: Rebuild, sign, and install

pwsh -File "skills/apk-reverse/scripts/rebuild-sign-install.ps1" `
    -ProjectDir "apktool_out" `
    -Install -Reinstall

The decode.ps1 script at skills/apk-reverse/scripts/decode.ps1 runs both jadx (for Java source reference) and apktool (for editable smali/resources) in a single command.

Key Source Files in reverse-skill

Understanding the repository structure helps with debugging and customization:

File Purpose
skills/apk-reverse/SKILL.md Official skill documentation with tool requirements and workflow overview
skills/apk-reverse/scripts/rebuild-sign-install.ps1 Main rebuild/sign/install automation script
skills/scripts/bootstrap-reverse.ps1 Missing tool auto-installer
skills/tool-index.md Tool path registry queried by Get-ToolPath
skills/apk-reverse/scripts/decode.ps1 Initial APK unpacking helper
docs/ARCHITECTURE.md High-level framework design documentation

These files implement the official, supported method for rebuilding and signing APKs within the reverse-skill ecosystem as designed by zhaoxuya520.

Summary

  • Use rebuild-sign-install.ps1 as the single entry point for APK rebuild and sign operations in reverse-skill
  • Tool discovery is automatic via PATH, tool-index.md, or bootstrap fallback—no manual configuration required
  • Debug keystores are auto-generated when missing, with 27-year validity for development use
  • Optional adb deployment via -Install and -DeviceSerial eliminates separate install steps
  • Custom output paths via -OutDir and -BaseName support CI/CD and organized build directories

Frequently Asked Questions

What tools does reverse-skill require for APK rebuilding?

The framework requires apktool, zipalign, apksigner, adb, and a Java runtime. According to the source code in bootstrap-reverse.ps1, missing tools are automatically downloaded and installed when first needed. You can verify tool detection by checking skills/tool-index.md after running any script.

Can I use reverse-skill on macOS or Linux?

Yes. All scripts are written in PowerShell Core (pwsh) and execute cross-platform. The bootstrap system detects your operating system and downloads appropriate tool binaries. File paths in parameters should use your platform's native format or PowerShell's automatic path translation.

How do I use my own keystore instead of the debug keystore?

The current version of rebuild-sign-install.ps1 automatically uses ~/.android/debug.keystore. To use a production keystore, you would need to modify the script's $KeystorePath variable or invoke apksigner manually after the alignment step. The script outputs the aligned APK path specifically to support this customization workflow.

What does the -Clean switch actually remove?

The -Clean switch deletes previous build artifacts matching the current BaseName in the output directory—specifically files ending in -unsigned.apk, -aligned.apk, and -signed.apk. It does not modify your apktool project directory or source smali files, making it safe to use during iterative development.

Have a question about this repo?

These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:

Share the following with your agent to get started:
curl -s "https://instagit.com/install.md"

Works with
Claude Codex Cursor VS Code OpenClaw Any MCP Client

Maintain an open-source project? Get it listed too →