Clean-Room Mobile App Replication with Intelligent Agents: Authorization, Specs, and Validation
This article explains a clean-room workflow for replicating mobile apps only in authorized scenarios: replicating your own app, replicating an app with written permission, or analyzing interactions for research. It covers compliance boundaries, a five-step framework from replication-level scoping to device automation, semantic-tree and screenshot analysis, specification generation, native and server-side reconstruction, and same-device validation. Readers will learn how to define acceptance levels (L0–L5), automate Android and iOS devices safely, convert UI observations into structured specs, implement backend behavior, and validate the replica against the original without reverse engineering or unauthorized data collection.
1. Applicability and Compliance Boundaries
The method discussed in this article applies only to three scenarios: replicating your own app, replicating an app for which written authorization has been obtained, and interaction analysis for research purposes. Before starting, the team must confirm the ownership of rights related to the target app’s copyright, trademarks, UI design, and core business logic. The replica must not use protected brand identifiers or proprietary visual assets, and it must not be listed or publicly released.
Before automating a physical device, the team must also read the target app’s terms of service. Many apps prohibit automated traversal, batch operations, or data collection. Violating these terms may lead to account suspension and may also create legal disputes.
The “clean-room replication” described here is a workflow. It observes only the app’s public interface and visible interaction results; it does not decompile installation packages, does not scrape or parse encrypted communications, and writes code from scratch based on observed specifications. The entire process follows a closed loop of “investigate, rebuild, verify, deliver”:
- Investigate: Within the authorized scope, take control of the test device and record UI structure, visual parameters, and interaction results.
- Rebuild: Based on the specification list, implement from scratch using native frontend technologies and server-side languages.
- Verify: Open both apps on the same device and compare them item by item.
- Deliver: After acceptance, organize code, templates, and documentation into reusable team assets.
2. Detailed Five-Step Framework
The following five-step framework turns the loop above into concrete operations. Each step has clear inputs and outputs, making team division and review easier.
1. Scoping: Define Replication Depth
Replication does not always require pixel-level consistency. This article divides replication goals into six levels, L0 through L5, with judgment criteria so teams can align on acceptance before work begins.
| Level | Judgment Criteria | Acceptance Method |
|---|---|---|
| L0 | Static pages only, no interaction | Screenshot comparison |
| L1 | Pages can navigate, controls respond, data are fixed samples | Page-by-page click-through review |
| L2 | Visual parameters within agreed tolerance, multi-screen navigation complete | Same-device dual-open comparison |
| L3 | Core functions genuinely run; static fake data are rejected | End-to-end testing of core flows |
| L4 | User data can be saved and restored; state persists across sessions | Check state after killing and restarting the process |
| L5 | Network requests, persistence, model calls, and exception handling all match the original app | Full-chain capture comparison (only for owned or authorized systems) |
This article uses a multimodal AI content generation app as an example, with the target set to L3. This level requires core functions to be genuinely usable, but it does not require the data sources and internal implementation to be identical to the original app.
2. Direct Device Connection: Automated Control
Android devices: In the phone’s “Settings,” find “About phone” and tap “Build number” about seven times to enable Developer Options. Then enter Developer Options and turn on “USB debugging.” After connecting to a computer with a data cable, run adb devices to confirm the device status is device. On first connection, the phone displays an “Allow USB debugging” dialog that requires manual confirmation; selecting “Always allow from this computer” is recommended.
During automation, the lock screen blocks input and affects screenshots. Before running, enable “Stay awake” in Developer Options and confirm that the test account is logged in. System permission dialogs must be handled manually before the run; the agent should not click authorization prompts on the user’s behalf.
iOS devices: iOS does not support adb and usually requires Xcode and a developer account. The team needs to compile and sign WebDriverAgent, install it on the device, and then trust the developer certificate under “General” and “VPN & Device Management” in Settings. Automation is based on the XCUITest framework and may only be used on owned devices or authorized test builds.
Regardless of platform, fixed delays should be added between adjacent operations to control request frequency. For operations involving billing, such as triggering a real content generation, a call limit should be set to avoid unexpected test charges.
3. Semantic Tree and Screenshot Parsing
This step is the most central part of the investigation phase. The intelligent agent needs to convert the interface into computable data.
On Android, common commands are as follows:
# Export the current UI control hierarchy (available on most Android versions)adb shell uiautomator dump /sdcard/window_dump.xmladb pull /sdcard/window_dump.xml ./dumps/home.xml# Capture the current screenadb exec-out screencap -p > ./shots/home.png# Get screen resolution and pixel density for unit conversionadb shell wm sizeadb shell wm density
Each node’s bounds attribute in the XML has the form [x1,y1][x2,y2], in physical pixels. To convert to dp, use the formula dp = px / (density / 160). Only dimensions obtained this way can be compared across different devices.
Visual parameters need to be estimated through image analysis. The background color can be read directly from the pixel value at a specified coordinate and converted to a hexadecimal color code. The corner radius can be estimated through edge detection. Font size can be converted from text height. These values are estimates, and the specification list should note the error range, for example ±1dp.
Two types of limitations should be noted. First, some pages set secure flags, so the system blocks screenshots and control content may not appear in the hierarchy tree. Second, content in WebViews and controls on custom-drawn canvases often cannot be fully represented in the hierarchy tree. In such cases, record them as “cannot be collected automatically” and supplement them through manual review.
4. Specification List Generation
The parsing results need to be organized into two documents that serve as the basis for reconstruction.
The screen-by-screen UI difference table records each page’s element composition and style parameters. Example fields are as follows:
| Page ID | Control ID | Type | Bounds (dp) | Text | Background Color | Corner Radius (dp) | Font Size (sp) | State |
|---|---|---|---|---|---|---|---|---|
| home | btn_create | Button | 16,620,359,668 | Start creating | #3366FF | 12 | 16 | Default |
The behavior audit table records state changes before and after each interaction:
| Interaction ID | Pre-state | Action | Post-state | Navigation Target | Prompt Text | Loading State |
|---|---|---|---|---|---|---|
| A-012 | home, logged in | Tap “Start creating” | Enter parameter page | create_params | None | Progress bar appears for about 2 seconds |
The behavior audit table provides a baseline for backend logic. For example, the table records the request structure triggered by a button, the success and failure prompt texts, and the duration of the loading state. These details must be matched one by one during server-side implementation.
5. Native and Server-Side Reconstruction and Acceptance
Frontend reconstruction: Android can use Kotlin with Jetpack Compose or XML layouts, and iOS can use SwiftUI. Restore page structure and styles according to the UI difference table, and bind interaction events and page states according to the behavior audit table.
Server-side reconstruction: The server is responsible for calling multimodal large model interfaces, managing user state, scheduling task queues, and returning results. Taking a video extension feature as an example, after the client submits a task, the server polls generation progress at fixed intervals; exponential backoff is recommended to avoid overly frequent requests. When generation is complete, the result is sent to the client through a callback URL. The callback must verify the signature to prevent forged requests. Each generation result should store a version number and the original task information for traceability and rollback.
Same-device acceptance: Install the replica app on the test phone, open it at the same time as the original app, and compare item by item. The checklist should include the following:
- First-screen presentation and launch speed
- Navigation hierarchy and back behavior
- Content and timing of prompt text (Toast, dialogs)
- Behavior of loading, empty, and error states
- Timing and wording of system permission dialogs
- Landscape/portrait switching, font scaling, and dark mode
- Recovery behavior after network interruption
3. Cost Dimensions
Cost consists of four parts. Teams should estimate each separately rather than relying on a single number.
- Labor: engineers familiar with the target technology stack and the time required to complete the first prototype
