Clean-Room Reconstruction of Mobile Apps: A Low-Cost Practical Guide

    This guide explains how to reconstruct a mobile app's behavior through clean-room methods—observing only public interfaces, interactions, and outputs—without reverse engineering protected code. It covers a five-stage workflow: fidelity grading (L0–L5), connecting to a real device in debug mode, dual-channel parsing of the control tree and screenshots, specification documents, and native/server rebuild with same-device acceptance testing. Readers will learn how to turn visual observations into verifiable specs, avoid common pitfalls, and stay within compliance boundaries.

    1. Why Rebuilding an App Is Not Reverse Engineering

    The most common misunderstanding in discussions about app reconstruction is equating “building a functionally equivalent product” with “decompiling someone else’s installation package.” The former is clean-room reconstruction: you observe only publicly visible interfaces, interactions, and output results, then write code from scratch to reproduce the same behavior. The latter involves disassembling protected code and carries far higher legal and compliance risks.

    This article focuses on the former. Its value is not in “copying a shell,” but in validating three things at very low cost: whether the interaction flow can be fully described, whether the effects can be reliably reproduced, and whether the engineering structure can be independently rebuilt. The “7 hours and 21 yuan” mentioned in the original practice is essentially a reference point for the scale of this kind of low-cost experimentation—the time went mainly into organizing specifications, and the cost went mainly into invoking generative capabilities, not into expensive toolchains.

    2. Overall Framework: Investigate, Rebuild, Verify, Deliver

    Drawing on the common “research–build–verify–deliver” approach in the industry, the whole process can be broken into five stages:

    1. Grading: decide whether the goal is “looks the same” or “works the same.”
    2. Direct device connection: let an AI coding tool take over a device with debugging enabled through terminal commands.
    3. Structure parsing: export the control tree and coordinates, and capture screenshots to extract visual parameters.
    4. Specification: produce a per-screen diff table and a behavior audit table, turning observations into executable documents.
    5. Rebuild and acceptance: write the native client and server, then run regression comparisons on the same device.

    The key design here is “specification first.” The interface seen by the human eye is fuzzy; only a specification written as a checklist can be reliably rebuilt and checked item by item during acceptance.

    3. Step 1: Grade the Reconstruction—Decide How Close Is Close Enough

    Without grading, reconstruction falls into endless pixel-level arguments. In practice, a six-level L0–L5 scale can be used:

    • L0: only the information architecture matches, with the same page navigation relationships.
    • L1: the layout skeleton matches, with major blocks in the same positions.
    • L2: visual parameters match, with aligned colors, corner radii, font sizes, and spacing.
    • L3: effects match, where the same input produces semantically equivalent output, with no static fake data.
    • L4: edge cases match, with the same behavior for exceptions, empty states, overly long text, and poor network conditions.
    • L5: performance and observability match, with comparable latency, failure rates, and log metrics.

    Setting the default target at L3 is a pragmatic choice: it rules out the self-deception of “a polished interface with hard-coded data” without getting bogged down in performance details too early. Once the grade is set, all later disputes have a basis for resolution.

    4. Step 2: Direct Device Connection—Turn the Device into a Programmable Terminal

    After a phone has debugging enabled and is connected to a computer, an AI coding tool can perform installation, launch, tapping, text input, log capture, and other operations through terminal commands. The illustrative command sequence below only expresses the flow and is not tied to a specific tool interface:

    1. # List connected devices
    2. devices_list
    3. # Install the package to be analyzed (placeholder name)
    4. install ./sample.apk
    5. # Launch the target screen
    6. shell am start -n com.example.app/.MainActivity
    7. # Export the current UI control structure
    8. shell uiautomator dump /sdcard/window.xml
    9. shell cat /sdcard/window.xml > ./window.xml
    10. # Capture the current screen
    11. shell screencap -p /sdcard/screen.png
    12. pull /sdcard/screen.png ./screen.png

    The most important lesson from this stage is: do not trust a single coordinate. Control positions drift across different resolutions and OS versions, so parsing results must be based primarily on “control identifier + relative hierarchy,” with coordinates as a supplement.

    5. Step 3: Dual-Channel Parsing of the Semantic Tree and Screenshots

    Exporting the control structure yields a semantic tree: each node carries its type, text, clickability, bounding box, and parent-child relationships. It answers “what is this, can it be clicked, and how does the hierarchy change after clicking.”

    Screenshots answer visual questions: primary and secondary colors, corner radius, font size hierarchy, shadows and dividers, and the position of empty-state illustrations. Aligning the two produces a “node–visual attribute” mapping table, which becomes the direct input for the native layout.

    In practice, it is recommended to capture three states for each screen: initial, loading, and result. Capturing only the initial state almost inevitably leads to rework during acceptance.

    6. Step 4: Specification Checklists—Turn Observations into Engineering Documents

    Two documents are the core deliverables.

    The per-screen UI diff table records “parameter differences between the original and the reconstruction on the same screen,” such as spacing deviations, font size tiers, and color values. The behavior audit table records “the state changes triggered by each operation,” such as whether a button is disabled after a tap, whether a second confirmation appears, and the failure message text and retry path.

    A compact audit table structure example:

    1. screen: result_page
    2. entry: [home_page.click_generate, history_page.open_item]
    3. states:
    4. - id: loading
    5. ui: progress_visible=true, action_disabled=true
    6. - id: success
    7. ui: media_visible=true, version_count=n
    8. - id: failure
    9. ui: toast_text="Generation failed", retry_entry=true
    10. transitions:
    11. loading -> success: on_task_done
    12. loading -> failure: on_error(timeout|content_policy)

    With this table, “matching effects” can be verified objectively rather than by subjective impression.

    7. Step 5: Rebuilding the Native Client and Server

    The native client implements the interface and interactions according to the specification tables, while the server provides task orchestration, state storage, and capability invocation. Generative capabilities should be integrated through a unified adapter layer that shields differences between providers and makes replacement and canary rollout easier:

    1. interface GenProvider {
    2. suspend fun submit(req: GenRequest): TaskId
    3. suspend fun query(id: TaskId): TaskState
    4. }
    5. class AdapterProvider(private val impl: GenProvider) : GenProvider by impl

    On the server side, four points deserve attention: task asynchrony and idempotency keys, result object storage and lifecycle management, failure retries and fallback, and structured logging and metrics reporting. If deployed on the cloud, you can combine general-purpose capabilities such as container platforms, object storage, message queues, logging services, and monitoring and alerting, avoiding binding business logic to specific infrastructure.

    8. Acceptance: Same-Device Comparison and Effect-Level Verification

    Acceptance should be carried out on the same device under the same network conditions, checking off the diff table item by item. Effect-level verification should cover at least four types of cases: real model invocation rather than hard-coded responses, completeness of continuous playback of long results, retention of multiple result versions with source attribution, and exception and timeout paths.

    It is recommended to script the acceptance process into a repeatable regression suite and rerun it after every change to avoid “fix one, break three.”

    9. Common Pitfalls and Compliance Boundaries

    • Capturing only the initial state, resulting in a missing state machine.
    • Relying on absolute coordinates, which breaks as soon as the device model changes.
    • Treating static fake data as a finished result, making L3 meaningless.
    • Ignoring empty states and poor network conditions, causing problems to surface all at once after delivery.
    • Ignoring compliance: do not decompile, do not capture non-public interfaces, do not copy protected assets or brand identifiers, and use reconstruction results only for learning, research, and prototypes of your own products.

    10. Conclusion

    The difficulty of clean-room reconstruction has never been writing code, but accurately translating “what you see” into “verifiable specifications.” The five steps—grading, direct connection, dual-channel parsing, specification, rebuild, and same-device acceptance—form a low-cost, reusable path. Combined with grading standards and regression scripts, individual developers and small teams can also complete a runnable prototype of a generative app within a day and reserve the budget for the effect polishing that truly matters.