Clean-Room Mobile App Replication: Compliance Boundaries and a Five-Step Workflow

    Large-model agents can help developers replicate mobile app interfaces and basic interactions only when rights are clear. This article presents a clean-room replication workflow for owned apps, apps with written authorization, or projects whose public materials explicitly permit secondary development. It covers compliance scoping, L0–L5 target levels, ADB-based device access, semantic-tree and screenshot parsing, specification tables, same-device acceptance, and engineering controls limited to authorized apps.

    Large-model agents can assist developers in replicating mobile app interfaces and basic interactions, but only when rights are clear. This article describes a five-step clean-room replication process while explaining its scope, acceptance methods, and common issues. The practices below apply to apps that you own, apps for which you have written authorization, or projects whose public materials explicitly permit secondary development.

    Introduction

    The core of clean-room replication is to avoid viewing source code and avoid decompiling binary files. Instead, the implementation is written independently based on observable interfaces and behavior. This approach reduces the risk of directly copying code, but it does not replace legal review. Interface layouts, icons, copy, brand identifiers, and data content may all be protected by copyright, trademark, or trade secrets. Therefore, the following checks should be completed before starting:

    1. Confirm app ownership. The app must be your own product, or you must have written authorization.
    2. Read the target app’s user agreement and confirm whether it prohibits interface capture, automated operations, or secondary development.
    3. List assets that need to be replaced, including icons, fonts, illustrations, and copy, and replace them with team-owned or commercially licensable assets.
    4. Keep inspection records and proceed to delivery only after manual review.

    Meeting these conditions only means that risk is controllable; it does not mean absolute compliance. When user data, account login, or payment functions are involved, legal and security teams also need to participate.

    1. Define the Boundaries First

    Clean-room replication reduces the risk of direct code copying, but interface layouts, icons, copy, brand identifiers, and data content may still be protected by copyright, trademark, or trade secrets. Before implementation begins, confirm ownership, review the target app’s terms of service, list assets that must be replaced, and retain inspection records for manual review. These checks make risk more controllable, but they are not a substitute for legal review. If user data, account login, or payment functions are involved, legal and security teams should also be included.

    2. Set the Target Level: Decide How Far to Replicate

    The replication outcome should be classified before work begins. This article divides results into six levels, L0 through L5:

    • L0: Restore only the static interface; controls do not respond to operations. Acceptance is based on screenshot comparison.
    • L1: Support page navigation, with data coming from local mock data. Acceptance checks whether all pages can be reached from one another.
    • L2: The interaction flow is complete, but data is still hard-coded. Acceptance checks whether the result of each operation path is correct.
    • L3: The default target. The interface and interactions are consistent, and core functions connect to a real backend.
    • L4 and L5: Add exception handling, performance metrics, and platform-native experience.

    L3 requires clarification of what “real backend” means. It can be a team-built service or a large-model API. If a large-model API is used, define the interface contract first, including request format, response fields, timeout, and retry count. API keys should be injected through environment variables or a secret management service and must not be written into code or logs. When an API call fails, the interface should show a clear message and provide a fallback, such as returning cached results or prompting the user to retry later. L3 acceptance cases should cover the core flow, such as input, submission, waiting, and result display, and each case should have pass criteria.

    3. Direct Device Access: ADB Authorization and Minimal Commands

    Android devices can be connected to a computer through ADB (Android Debug Bridge), allowing an intelligent agent to take screenshots, read the interface tree, and simulate taps. The following conditions must be met before operation:

    1. Enable developer options in the phone’s Settings and turn on USB debugging.
    2. Connect the phone to the computer with a data cable. On the first connection, confirm the RSA fingerprint authorization prompt on the phone.
    3. Run adb devices on the computer. The device status must show device to indicate a normal connection. If it shows unauthorized, the phone has not yet authorized the connection.
    4. Use a dedicated test device or emulator. Do not run automation scripts on a personal primary phone, to avoid accidental operations on logged-in accounts and private data.

    After confirming the connection, run the following two basic commands:

    1. adb shell uiautomator dump /sdcard/window.xml
    2. adb exec-out screencap -p > screen.png

    The first command exports the interface control tree, and the second saves the current screen screenshot. System tools differ across Android versions. If a command reports an error, first check the device system version and tool output. When using cloud real devices or device farms, confirm that the provider allows automated testing and follow its terms of use.

    iOS is different. Third-party iOS apps without developer authorization usually cannot export a control tree at the same granularity. This article focuses on Android as the primary scenario. iOS solutions should be based on team-owned apps and implemented through official test frameworks such as XCUITest.

    4. Semantic Tree and Screenshots: Dual Parsing

    Relying only on screenshots makes it difficult for a model to determine control hierarchy. Relying only on the control tree lacks visual details such as color, corner radius, and shadow. Therefore, it is recommended to use both types of data together.

    The control tree provides type, hierarchy, boundary coordinates, and clickable attributes. Screenshots supplement visual information. Below is a cleaned-up example:

    1. {
    2. "node": "TextView",
    3. "bounds": "[100,200][400,250]",
    4. "text": "Submit",
    5. "clickable": true,
    6. "visual_meta": {
    7. "font_size": "16sp",
    8. "bg_color": "#1A73E8",
    9. "corner_radius": "8dp"
    10. }
    11. }

    The source of these fields must be distinguished. Control boundaries, text, and clickable attributes come from the control tree and can be used directly. Visual parameters such as font size and corner radius mostly come from screenshots and require screen density conversion. For example, the same pixel size corresponds to different dp values on devices with different densities. After extraction, calibrate against the dimensions of known controls, then perform manual spot checks. Values extracted from screenshots should be marked as “estimated values” and must not be used directly as design-spec parameters.

    5. Specification Checklists: Fields for Two Tables

    Parsing results need to be converted into documents usable for development, including a screen-by-screen UI difference table and a behavior audit table.

    The screen-by-screen UI difference table can use the following headers: Page ID, Control path, Property, Expected value, Actual value, Severity, Notes. Example:

    Page ID Control path Property Expected value Actual value Severity Notes
    home_01 root/Button[2] Background color #1A73E8 #1A73D8 Minor Estimated value

    The behavior audit table records the causal chain of state changes. Its headers can be: Trigger action, Precondition, Page navigation, Network request, Load time, End state, Exception branch.

    Trigger action Precondition Page navigation Network request Load time End state Exception branch

    For example, after tapping “Submit,” the page enters a loading state and initiates an API request; after the request succeeds, the result page is displayed. Load time should be measured multiple times and the median recorded, not a single value.

    6. Code Rebuild and Same-Device Acceptance: Handling Dynamic Content

    Generated code must be compiled and installed on the test device, then compared with the reference app. Three types of interference must be handled during comparison.

    The first is dynamic content, such as time, avatars, and recommendation lists. Before acceptance, fix the test data or mark these areas as ignore regions. The second is network variability. Repeat runs should be performed under the same network conditions, and failure counts should be recorded. The third is animation. Wait for animations to finish before taking screenshots.

    Screenshot comparison usually uses pixel-by-pixel differences. Before comparison, mask dynamic regions, then calculate the difference ratio. Difference thresholds need to be determined experimentally for each project; this article does not provide a universal value. A feasible starting point is to allow small color deviations in static regions, generate annotated images for regions exceeding the threshold, and send them for human judgment. Human review conclusions should be recorded as the basis for subsequent iterations.

    If acceptance fails, the agent can modify the code according to the difference table and then rerun acceptance. If multiple iterations still fail, return to the requirements level to determine whether the target level is too high or the difference itself requires a design decision.

    7. Engineering Implementation: Authorized Apps Only

    After the process is packaged as a skill library, teams can launch tasks through a unified entry point, such as entering the app package name, selecting the target level, and specifying the test device. To prevent abuse, this entry point should add access control: only registered owned apps or authorized apps are allowed to run, and each task should record the owner, authorization basis, and intended use of output.

    For cloud deployment, tasks require substantial device debugging and model inference. Enterprises can use container platforms and compute instances for elastic scheduling, and store screenshots, UI trees, and generated code in a unified object store.