Metadata-Version: 2.4
Name: android-apk-mcp
Version: 0.3.0
Summary: Local MCP server and CLI for archiving, comparing and analyzing Android APK releases
Project-URL: Repository, https://github.com/ahmedsaeed1-eng/android-apk-mcp
Project-URL: Issues, https://github.com/ahmedsaeed1-eng/android-apk-mcp/issues
Keywords: android,apk,mcp,adb,dex,flutter
Classifier: Development Status :: 3 - Alpha
Classifier: Environment :: Console
Classifier: Intended Audience :: Developers
Classifier: Programming Language :: Python :: 3
Classifier: Topic :: Software Development
Requires-Python: >=3.11
Description-Content-Type: text/markdown
Requires-Dist: mcp<2,>=1.30.0
Provides-Extra: dev
Requires-Dist: black==25.12.0; extra == "dev"
Requires-Dist: ruff==0.15.0; extra == "dev"

# Android APK MCP

<!-- mcp-name: io.github.ahmedsaeed1-eng/android-apk-mcp -->

[![CI](https://github.com/ahmedsaeed1-eng/android-apk-mcp/actions/workflows/ci.yml/badge.svg?branch=main&event=push)](https://github.com/ahmedsaeed1-eng/android-apk-mcp/actions/workflows/ci.yml)
[![Release](https://img.shields.io/github/v/release/ahmedsaeed1-eng/android-apk-mcp?style=flat-square)](https://github.com/ahmedsaeed1-eng/android-apk-mcp/releases)
[![GitHub stars](https://img.shields.io/github/stars/ahmedsaeed1-eng/android-apk-mcp?style=flat-square&logo=github)](https://github.com/ahmedsaeed1-eng/android-apk-mcp/stargazers)
[![Python 3.11+](https://img.shields.io/badge/Python-3.11%2B-3776AB?style=flat-square&logo=python&logoColor=white)](pyproject.toml)
[![MCP stdio](https://img.shields.io/badge/MCP-stdio-7356BF?style=flat-square)](#connect-an-mcp-client)

[![Windows](https://img.shields.io/badge/Platform-Windows-1675C1?style=flat-square)](#windows)
[![Linux](https://img.shields.io/badge/Platform-Linux-C7921D?style=flat-square&logo=linux&logoColor=white)](#linux-and-macos)
[![macOS](https://img.shields.io/badge/Platform-macOS-5D6270?style=flat-square&logo=apple&logoColor=white)](#linux-and-macos)
[![Codex](https://img.shields.io/badge/Client-Codex-4B5464?style=flat-square)](#codex)
[![Claude Desktop](https://img.shields.io/badge/Client-Claude%20Desktop-C05E38?style=flat-square&logo=claude&logoColor=white)](#claude-desktop)

[![ADB import](https://img.shields.io/badge/Android-ADB%20import-247C56?style=flat-square&logo=android&logoColor=white)](#analyze-an-apk-or-a-device)
[![Split APKs](https://img.shields.io/badge/APK-split%20sets-247C56?style=flat-square)](#analyze-an-apk-or-a-device)
[![SHA-256 verification](https://img.shields.io/badge/Integrity-SHA--256-0B7784?style=flat-square)](#analyze-an-apk-or-a-device)
[![DEX via JADX](https://img.shields.io/badge/DEX-JADX-286B96?style=flat-square)](#optional-analysis-engines)
[![Flutter AOT via Jadart](https://img.shields.io/badge/Flutter%20AOT-Jadart-096A9E?style=flat-square&logo=flutter&logoColor=white)](#optional-analysis-engines)
[![Android resources](https://img.shields.io/badge/Resources-compiled%20XML-276C82?style=flat-square)](#analysis-output)
[![Smali via Apktool](https://img.shields.io/badge/DEX-Smali%20via%20Apktool-286B96?style=flat-square)](#optional-smali-pass)
[![Native ELF](https://img.shields.io/badge/Native-ELF%20inventory-5C5484?style=flat-square)](#analysis-output)
[![JSON reports](https://img.shields.io/badge/Reports-JSON-546581?style=flat-square)](#analysis-output)
[![Ruff](https://img.shields.io/badge/Lint-Ruff-62479A?style=flat-square&logo=ruff&logoColor=white)](.github/workflows/ci.yml)
[![Black](https://img.shields.io/badge/Format-Black-343A46?style=flat-square)](.github/workflows/ci.yml)

Android APK MCP archives, compares, and analyzes Android releases locally. The CLI and MCP server can copy a base APK and every installed split for a selected package from an authorized Android device. The analysis recovers supported DEX and Flutter AOT output, decodes compiled Android resources, and inventories native ELF libraries.

## Install

Requires Python 3.11+. Install the package from this repository or use the wheel from [GitHub Releases](https://github.com/ahmedsaeed1-eng/android-apk-mcp/releases).

```sh
git clone https://github.com/ahmedsaeed1-eng/android-apk-mcp.git
cd android-apk-mcp
python -m pip install .
android-apk-mcp --help
```

The setup scripts create a project virtual environment and write local MCP client configuration. The archive, comparison, and manifest tools work with the Python installation above.

### Windows

```powershell
& .\scripts\setup.ps1
& .\.venv\Scripts\Activate.ps1
android-apk-mcp --help
```

### Linux and macOS

Install Python 3.11+ with the `venv` module and Bash. On Ubuntu, install `python3-venv` if the system Python does not include it.

```bash
bash scripts/setup.sh
source .venv/bin/activate
android-apk-mcp --help
```

## Analyze an APK or a device

```sh
android-apk-mcp engines
android-apk-mcp analyze-apks base.apk split_config.arm64_v8a.apk
android-apk-mcp devices
android-apk-mcp analyze-device org.example.app --serial DEVICE_SERIAL
android-apk-mcp analysis-inputs ANALYSIS_ID --limit 25
```

For direct import, connect the Android device, enable USB debugging, and approve the normal Android prompt. With one connected device, the serial is optional. Import verifies that every installed APK still belongs to the same installation and checks each copied file's length. Use packages that you own or have permission to analyze.

Use `import`, `list`, `compare`, and `export` to work with archived versions. Set `--library` before the command or set `ANDROID_APK_MCP_LIBRARY` to choose a storage directory. Editable installs use the checkout's `data/` directory. Wheels and other regular installs use a per-user directory.

### Optional analysis engines

- **DEX** uses [JADX 1.5.6](https://github.com/skylot/jadx/releases/tag/v1.5.6) and Java 11 or newer. Set `MCP_JADX_JAR` to the absolute path of the release's bundled JAR. An editable install also detects `.tools/jadx/jadx.jar` in the checkout.
- **Flutter AOT** uses [Jadart](https://github.com/IR0NBYTE/Jadart) with its disassembly extra. The setup scripts pin the same [source revision](https://github.com/IR0NBYTE/Jadart/tree/ad51958555a3aea1c65315eaa883f30effccc40a/framework). The server uses Jadart from its Python environment or the absolute executable path in `MCP_JADART_EXE`.
- **USB import** uses [Android Platform Tools](https://developer.android.com/tools/releases/platform-tools). Put `adb` on PATH.

On Linux and macOS, install Git, curl, and Java, then run:

```bash
bash scripts/setup-analysis.sh
.venv/bin/android-apk-mcp engines
```

The Bash installer checks the official JADX download against its pinned SHA-256 and verifies the installed Jadart and Capstone runtime. To install one engine, pass `--jadx-only` or `--jadart-only`.

On Windows, download the bundled JAR from the JADX CLI distribution and run:

```powershell
& .\scripts\setup-analysis.ps1 -JadxJar 'C:\Tools\jadx\lib\jadx-1.5.6-all.jar'
& .\.venv\Scripts\android-apk-mcp.exe engines
```

The engines process APK contents on your computer. See [Third-party components](THIRD_PARTY.md) for the projects and pinned sources.

### Analysis output

The analysis directory contains `report.json`, an inventory, and artifacts tied to the original APK hash, split, and member.

| Input | Output |
| --- | --- |
| DEX and ARM64, built in | Dalvik register operations and branch graphs, or ARM64 instructions and register effects |
| DEX | Reconstructed Java and separate low-level fallback files from JADX |
| DEX, optional | Smali output from the pinned Apktool release |
| Flutter AOT | Approximate Dart or verified class structure from Jadart |
| Compiled Android resources | Decoded manifests, resource tables and files by split, with a built-in XML fallback |
| Native libraries | ELF architecture, load segments, sections and shared-library dependencies |

Inspect each stage status to see which inputs were recovered and which hit format, tool, or resource limits. Static reconstruction cannot recover the original source exactly. Native reports describe ELF structure and dependencies.

Per-DEX reports can include a short-class-name signal from a bounded sample. Short names are a heuristic and do not identify the tool that produced them.

### Built-in code and XML readers

Use the release ID from `import` or `list`. These commands run locally with Python and report the SHA-256 of the APK containing the selected member.

```sh
android-apk-mcp decode-dex RELEASE_ID --class 'Lorg/mcp/demo/MainActivity;' --method onCreate --signature '(Landroid/os/Bundle;)V'
android-apk-mcp decode-arm64 RELEASE_ID lib/arm64-v8a/libapp.so --instructions 128
android-apk-mcp decode-xml RELEASE_ID AndroidManifest.xml
```

Use `--split` for a member in an installed split, `--member` for a different root DEX, or `--symbol` to select an exact ARM64 function. The corresponding MCP tools are `decode_dex_method`, `decode_arm64_function`, and `decode_android_xml`.

The DEX reader supports standard little-endian DEX versions 035–040. Its register pseudocode reports the normal control-flow blocks and leaves unsupported instruction forms visible as bytecode. The ARM64 reader labels an executable-section sample when a function boundary is unavailable. ARM64 coverage counts decoded and unknown instruction words. The XML reader preserves numeric resource references where names are unresolved. JADX supplies resource-table decoding and whole-APK Java output, Apktool supplies optional Smali output, and Jadart supplies Flutter AOT recovery.

### Optional Smali pass

Download the [official Apktool 3.0.3 JAR](https://github.com/iBotPeaches/Apktool/releases/tag/v3.0.3), set `MCP_APKTOOL_JAR` to its absolute path, and run:

```sh
android-apk-mcp analyze-apks --smali base.apk feature.apk
# Or analyze an existing release:
android-apk-mcp analyze RELEASE_ID --smali
```

The JAR must match the release SHA-256. Apktool receives staged DEX entries and publishes Smali by split. In Codex or Claude Desktop, set `MCP_APKTOOL_JAR` in the server's environment and pass `include_smali: true` to `start_analysis`.

### Review a release you maintain

```sh
android-apk-mcp review-manifest RELEASE_ID
android-apk-mcp review-source path/to/config.py
```

The manifest review reports the declared or default setting, its origin, and components that warrant review. A reference to Network Security Config identifies where to look for per-domain rules. Component findings describe declarations. Credential findings examine one source file at a time and return candidate types and line and column numbers with values redacted.

### Runtime measurements

For an app you can build and benchmark, run [Jetpack Macrobenchmark](https://developer.android.com/topic/performance/benchmarking/macrobenchmark-overview) and pass the exported benchmark JSON to the CLI:

```sh
android-apk-mcp runtime-report benchmarkData.json
```

The summary includes metric ranges and medians from recorded runs. You can also put the JSON in the local inbox and use `summarize_android_benchmark` through MCP.

## Connect an MCP client

Install the package in the Python environment used by your client. The server uses local stdio and returns structured tool results.

### Codex

Add the server to your Codex configuration. Use the absolute path to `.venv/bin/python` or `.venv\Scripts\python.exe`.

```toml
[mcp_servers.android-apk-library]
command = "/absolute/path/to/python"
args = ["-m", "android_apk_mcp.cli", "serve"]
```

### Claude Desktop

Add the entry under `mcpServers` in the Claude Desktop configuration. An absolute Python path lets the client start the correct environment from the desktop.

```json
{
  "mcpServers": {
    "android-apk-library": {
      "command": "/absolute/path/to/python",
      "args": ["-m", "android_apk_mcp.cli", "serve"]
    }
  }
}
```

### Available tools

| Tools | Purpose |
| --- | --- |
| `list_inbox`, `import_release`, `export_release` | Import APK sets and export verified copies |
| `list_releases`, `inspect_release`, `list_manifest`, `list_files` | Browse releases, declared components and package entries |
| `compare_releases` | Compare APK hashes, permissions, components, splits and entry metadata |
| `check_analysis_engines`, `list_android_devices` | Check local engine and device availability |
| `start_analysis`, `start_device_analysis`, `get_analysis`, `list_analyses` | Start and track analysis jobs |
| `list_analysis_inputs` | Page through input provenance and stage results |
| `decode_dex_method`, `decode_arm64_function` | Read selected instructions with the built-in Dalvik or ARM64 reader |
| `decode_android_xml` | Decode an archived Android manifest or resource XML |
| `review_android_manifest` | Review archived application flags and component declarations |
| `review_source_credentials` | Locate redacted credential candidates in one source file placed in the inbox |
| `summarize_android_benchmark` | Read metrics from an AndroidX Benchmark JSON export |
| `record_behavior`, `implementation_brief` | Save developer observations and summarize a release |

Place APKs in the library's `inbox/` for MCP imports. An analysis start returns an ID. Read its progress with `get_analysis`; completed results include paths to generated artifacts.

## Development

The repository includes an original [Java sample](demo/README.md) with two versions and a [Flutter ARM64 sample](demo/flutter/README.md). They are built using the Android and Flutter SDKs.

```sh
python -m pip install -e '.[dev]'
python -m ruff check src tests
python -m black --check src tests
python -m unittest discover -s tests -v
```

Ubuntu CI builds the Java and Flutter APKs and runs the full suite with both analysis engines. macOS CI runs the same tests using those fixtures with its own engine installations. Windows CI builds the Java APKs and exercises JADX and the MCP lifecycle. Release checks also install and run the wheel outside the checkout.

See [Contributing](CONTRIBUTING.md), [Changelog](CHANGELOG.md), [Security reporting](SECURITY.md), and [Third-party components](THIRD_PARTY.md).
