A Five-Step Framework for Agent-Assisted App Replication

    This article outlines a clean-room methodology for replicating an app's functionality based solely on observable UI and interaction behavior, without reading the target app's source code or decompiled output. It covers five stages: scoping the replication level, capturing UI data from a real device via ADB, parsing control trees into semantic snapshots, producing UI diff and behavior audit specifications, and rebuilding both client and server for side-by-side acceptance testing. The article also defines four replication levels (L0–L3) with corresponding acceptance criteria, and provides ADB commands and a Python script for extracting clickable elements from a UI dump.

    Preface: Defining the Scope

    This method applies to two scenarios. The first is replicating a team’s own product for platform migration or code refactoring. The second is aligning features with a partner’s product after obtaining explicit written authorization. Replicating someone else’s app without authorization may raise copyright, trademark, terms-of-service, and non-compete issues. Before starting, teams should confirm the scope with legal counsel and avoid collecting any personal user data. The commands in this article are intended only for capturing UI structure and screenshots, and should be run using test accounts.

    1. Overall Approach: Observable Behavior as the Spec

    The core idea of this clean-room replication approach is that the team does not read the target app’s source code or decompiled artifacts. Instead, requirements are derived entirely from observed UI and interaction behavior. The workflow has five stages:

    1. Level assessment: Define the target replication level and acceptance criteria.
    2. Real-device capture: Connect a physical device via ADB, perform actions, and capture the control tree and screenshots.
    3. Semantic parsing: Merge the control tree with screenshots to produce semantically annotated visual snapshots.
    4. Spec generation: Compile UI diff tables and behavior audit tables as the basis for coding.
    5. Dual-side rebuild and acceptance: Implement the client and server separately, then compare them side by side with the original.

    2. Level Assessment: Defining How Far to Replicate

    This article defines four replication levels, L0 through L3. L4 and above are out of scope here; teams that need higher levels should define their own criteria and acceptance standards.

    • L0: Static screenshots match, with no interaction requirements. Acceptance: screen-by-screen screenshot comparison.
    • L1: Pages are scrollable, and layout remains stable across two or more screen sizes. Acceptance: check for misalignment on devices with different resolutions.
    • L2: Core controls are interactive and include basic logic, such as toggles, input validation, and page navigation. Acceptance: execute each item in the behavior audit table.
    • L3: Behavior and UI are both consistent. State transitions show no perceptible difference from the original within the paths covered by the audit checklist. Acceptance: operate two devices side by side and record whether each state matches the original.

    For time-consuming operations, such as video generation, L3 requires that the server perform real computation and display the actual result. An entry point that only shows mock data or a static placeholder does not meet the L3 bar.

    3. Real-Device Capture: Prerequisites for a Direct ADB Connection

    Before capturing data, complete the following setup:

    1. Enable Developer Options and USB debugging on the device.
    2. Connect the device to the computer with a USB cable and confirm the debugging authorization prompt on the device.
    3. Run adb devices and confirm the device status shows as device.
    4. Record the Android version, device model, resolution, and DPI, and include them in the capture report.

    Example capture commands:

    1. adb shell uiautomator dump /sdcard/window_dump.xml
    2. adb pull /sdcard/window_dump.xml ./snapshots/
    3. adb shell screencap -p /sdcard/screen.png
    4. adb pull /sdcard/screen.png ./snapshots/

    Capture results come with the following constraints:

    • Results are directly comparable only when captured on the same device model and the same OS version.
    • Rendering differs between real devices and emulators, which affects screenshot pixel values.
    • uiautomator dump relies on accessibility semantics. On pages built with WebView, Flutter, or Jetpack Compose, the control tree may be missing nodes or text. For these pages, supplement the data with manual annotation on screenshots or with the debugging tools built into the respective framework.
    • Each capture represents only a single snapshot in time and does not cover every possible page state. Loading states, error states, and empty states need to be captured separately.

    4. Semantic Parsing: Aligning the Control Tree with Screenshots

    The script below extracts key fields from the control tree.

    1. import xml.etree.ElementTree as ET
    2. def parse_dump(xml_path: str) -> list[dict]:
    3. tree = ET.parse(xml_path)
    4. items = []
    5. for node in tree.iter("node"):
    6. items.append({
    7. "resource_id": node.attrib.get("resource-id", ""),
    8. "class": node.attrib.get("class", ""),
    9. "text": node.attrib.get("text", ""),
    10. "clickable": node.attrib.get("clickable") == "true",
    11. "bounds": node.attrib.get("bounds", ""),
    12. })
    13. return items
    14. if __name__ == "__main__":
    15. for n in parse_dump("snapshots/window_dump.xml"):
    16. if n["clickable"]:
    17. print(n["class"], n["text"], n["bounds"])

    The bounds field follows the format [x1,y1][x2,y2], with coordinates in the same space as screenshot pixels. Example output:

    1. android.widget.Button Try Now [48,1620][1032,1764]
    2. android.widget.TextView Home [0,0][1080,120]