A Practical Guide to Low-Cost, AI Agent-Driven Clean-Room Replication of Mobile Apps
This article introduces a practical approach to clean-room replication of mobile applications driven by AI coding agents. Unlike traditional reverse engineering, this method relies solely on observing public UI and interactions on a physical device to rebuild a functionally equivalent native app. It details a four-phase methodology—Study, Build, Check, Ready—and a five-step engineering framework covering replication grading, ADB direct connection, dual-channel parsing, difference specification, and same-device validation. A real-world case study demonstrates that this approach significantly reduces development costs and technical barriers while maintaining compliance.
A Practical Guide to Low-Cost, AI Agent-Driven Clean-Room Replication of Mobile Apps
1. Background: From Web to Mobile App Replication
In recent years, replicating a website using large language model (LLM) coding agents is no longer novel—capturing screenshots, analyzing structures, and rewriting frontend code is a well-established workflow. However, replicating mobile apps is significantly more complex: the interface is rendered in a closed native environment, interaction states are scattered across page stacks, and network requests are often encrypted with strict signatures.
Traditional mobile reverse engineering typically relies on decompilation tools or runtime hook frameworks to directly analyze the target app’s binary code and network traffic. This path is not only technically demanding but also carries clear legal and compliance risks. This article introduces a completely different path: Clean-room Replication. This approach only observes the publicly presented interface and interaction results of the app on a real device, completely avoiding contact with its internal implementation, and rewriting a functionally equivalent native app from scratch.
The entire process is driven by an AI coding agent. Developers only need an Android phone with USB debugging enabled, a computer, and a minimal budget for model API calls. In my practice, replicating an AI product featuring image generation, video generation, and video editing took about 7 hours, with a model API cost of approximately 21 RMB.
2. Core Methodology: Study, Build, Check, Ready
The concept of clean-room replication originates from classic practices in software engineering: to avoid copyright disputes, the replicator can only refer to the “observable behavior” of the target system without accessing its source code or internal documentation. Applied to the mobile scenario, this can be distilled into a four-phase cycle:
- Study: Operate the target app on a real device, exhausting all pages, popups, states, and interaction paths, and recording every observable detail.
- Build: Based on the study output, write brand new native client and corresponding server-side code.
- Check: Install both the replicated and original versions on the same device, comparing differences screen by screen and feature by feature.
- Ready: Once differences converge to an acceptable threshold, package and archive the project, forming a foundation for secondary development.
These four phases are not executed linearly just once, but as an iterative cycle. Every discrepancy found during the Check phase is fed back into the Study and Build phases for correction until convergence is reached.
3. Five-Step Implementation Framework
Guided by the above methodology, I have solidified the implementation process into five engineering steps.
Step 1: Replication Grading (L0–L5)
First, clarify “how much to replicate.” It is recommended to divide the replication target into six levels:
- L0: Replicate only the static skeleton of the core page layout.
- L1: High visual fidelity for main pages, but using placeholder mock data.
- L2: Main interaction links can be clicked and navigated, with partial integration of real data.
- L3: Interface and functional effects are consistent, with all data coming from a real backend, rejecting static mock data.
- L4: Edge states (loading, empty, error, network exception) are fully aligned.
- L5: Performance experience (startup speed, list smoothness, animation frame rate) is also consistent.
In practice, it is recommended to default to L3 as the acceptance baseline—“looking alike” is not enough; it must “function alike” too. L4 and L5 can be pursued based on project needs. The significance of grading is to prevent scope creep: without clear level definitions, replication work can easily get bogged down in an endless quagmire of detail polishing.
Step 2: ADB Direct Connection to Physical Device
This is the key infrastructure of the entire solution. After enabling developer options and USB debugging on the Android device, connect it to the computer via a data cable. The coding agent can directly take over the device using terminal commands:
# Verify device connectionadb devices# Capture current screenadb shell screencap -p /sdcard/screen.pngadb pull /sdcard/screen.png# Dump current UI hierarchyadb shell uiautomator dump /sdcard/ui.xmladb pull /sdcard/ui.xml# Simulate tap and swipeadb shell input tap 540 1200adb shell input swipe 540 1600 540 400 300
The key point is that the AI agent can autonomously execute these commands: “seeing” the interface after taking a screenshot, “reading” the control tree after a dump, and “operating” the phone using input commands, forming a complete perception-decision-action closed loop. This effectively turns the agent into a tireless test engineer capable of exploring the target app page by page.
Step 3: Dual-Channel Parsing with Semantic Tree and Screenshots
Screenshots alone are insufficient because they cannot accurately express control boundaries and clickable areas; similarly, a control tree alone is insufficient because rendering details (colors, rounded corners, font sizes, shadows) cannot be restored from structural information. Therefore, a dual-channel parallel approach is necessary:
- Structure Channel: Parse the XML exported by uiautomator to extract the class name, resource ID, text, boundary coordinates, and clickable properties of each control, reconstructing the page’s semantic layout tree.
- Visual Channel: Perform pixel-level analysis on the screenshot to extract theme color values, corner radii, typography scales, spacing systems, and icon styles, summarizing the target app’s design specifications (Design Tokens).
After cross-validation between the two channels, a “Page Specification Document” is output, precise to the size, position, color, and behavior of every control. This document serves as the single source of truth for the subsequent build.
Step 4: Specification of Differences List
During the build process, two tables need to be continuously maintained:
- Screen-by-Screen UI Difference Table: Records visual differences between the replicated and original versions item by item, including the deviation location, deviation amount, and repair priority.
- Behavior Audit Table: Records state changes before and after each interaction action—for example, “Click generate button -> progress bar appears -> returns to result page after about 30 seconds -> generation history automatically appends a record.”
The behavior audit table is particularly crucial. Many replication projects fail not because the interface looks wrong, but because the state machine is incorrect: the original app might pop up a confirmation box after an operation, retain historical versions, or record image attribution. These implicit behaviors can only be fully captured through systematic operational audits.
Step 5: Native Client and Server Rebuild & Same-Device Validation
With the specification document and audit table in hand, the rebuild can begin:
- Client: Use Kotlin to write the Android native client, implement a component library according to the design specs, and then assemble the pages and navigation.
- Server: Use Python to implement the business backend, integrating real model inference capabilities (e.g., using cloud object storage to save generated results, message queues to decouple asynchronous generation tasks, and logging services to record call chains), ensuring all UI data comes from real APIs rather than hardcoded mock data.
The acceptance phase performs a “same-device comparison”: install both the original and replicated versions on the same physical device, compare them side-by-side screen by screen, and backfill the difference table to drive the next iteration until the L3 standard is met—including real agent calls, full playback of long tasks, and multi-version retention.
4. Cost and Experience Summary
The entire process took about 7 hours, with a model API cost of around 21 RMB. The reason the cost can be kept so low lies in two core factors: first, the agent autonomously completed a large amount of repetitive screenshot, dump, and comparison work; second, the five-step framework transformed the vague requirement of “replication” into a checklist-able engineering task, drastically reducing rework.
At the same time, it is essential to emphasize compliance boundaries: clean-room replication is suitable for learning, research, and verifying one’s own engineering capabilities. The replicated output should not be directly used for commercial distribution, nor should it infringe upon the original product’s trademarks, assets, or intellectual property. For independent developers, a more reasonable use of this workflow is as a scaffold to quickly build similar products—once the methodology is mastered, the barrier to building an AI generation app from scratch is significantly lowered.
