Clean-Room Mobile App Replication in 7 Hours for CNY 21
This practical guide presents a clean-room methodology for recreating an AI image and video generation app without reverse engineering or dynamic instrumentation. It covers fidelity levels, device automation, dual-channel UI analysis, behavioral auditing, native client and backend reconstruction, same-device acceptance testing, cost reduction, common pitfalls, reusable skill packaging, and compliance boundaries.
1. Why Choose Clean-Room Replication?
In mobile app development, “replication” is often misunderstood as a combination of decompilation and dynamic instrumentation. This approach creates compliance risks and typically produces obfuscated bytecode rather than maintainable engineering code.
A more defensible approach is clean-room replication: observe only publicly visible interfaces and interaction results, avoid protected implementation details, and independently rebuild the client and server from scratch. The output is not “guessed code,” but a verifiable specification and an independent implementation.
The subject of this exercise was an AI image and video generation app with text-to-image, image-to-video, video editing, duration extension, and multi-version management capabilities. No decompilation tools or dynamic instrumentation frameworks were used. Instead, the process followed a reusable methodology built around:
Investigate → Rebuild → Verify → Deliver
2. Define the Target First: Fidelity Levels from L0 to L5
The most common reason replication projects fail is not a lack of technical capability, but an unclear target. The required fidelity level must be defined before development begins. Otherwise, the project may repeatedly shift between pixel-perfect reproduction and basic functional completeness.
- L0 — Information-level fidelity: Reproduce the information architecture and copy.
- L1 — Structural fidelity: Match the page hierarchy and navigation relationships.
- L2 — Visual fidelity: Approximate colors, corner radii, font sizes, and spacing.
- L3 — Effect-level fidelity: Match interaction results and reject static fake data. This is the default target.
- L4 — State-level fidelity: Cover error states, loading states, retries, permission denials, and other branches.
- L5 — Pixel-level fidelity: Align interfaces pixel by pixel. This is highly expensive and is generally reserved for critical pages.
Choosing L3 by default is a practical compromise. It requires all data to be produced through real execution paths without demanding pixel-perfect visual alignment, keeping the total cost within a reasonable range.
3. The Five-Step Workflow
1. Connect Directly to the Device
After enabling the phone’s built-in USB debugging capability and connecting it to a computer, an AI coding agent can execute debugging commands through a terminal to install, launch, interact with, and capture the app.
The key is to represent device operations as stable primitives rather than allowing the model to generate arbitrary commands:
connect(device_id)install(apk_path)launch(package)tap(x, y) / swipe(p1, p2) / input(text)dump_hierarchy() -> xmlcapture() -> pngobserve() -> { xml, png, timestamp }
Once operations are converted into primitives, every later step becomes a composition of these building blocks. This greatly reduces the model’s output uncertainty.
2. Analyze Both the Semantic Tree and Screenshots
A single analysis channel will inevitably lose information. The exported view hierarchy provides structure, text, clickability, and precise coordinates, but it does not capture colors or corner radii. Screenshots provide visual ground truth but lack semantic information.
Aligning both channels by timestamp allows them to complement each other:
{"screen": "home","nodes": [{"id": "prompt_input","type": "EditText","bounds": [48, 620, 1032, 780],"visual": {"bg": "#1C1C1E","radius": 24,"font": 15}}],"actions": ["tap", "input", "scroll"]}
3. Create a Formal Specification: Two Tables Make the Difference
Use two structured tables to turn observations into a reproducible specification:
- Screen-by-screen UI difference table: Use screens as rows and record layout, controls, visual properties, target values, and measured values.
- Behavior audit table: Use state transitions as rows and record trigger conditions, prerequisite states, expected results, and actual results.
The behavior audit table is the core asset for L4-level coverage. It turns “tap around and see what happens” into a regression test suite that can be rerun automatically after every change.
4. Rebuild the Native Client and Backend
The client is implemented with native Android development technologies for the interface and interaction logic. The backend is implemented with a scripting language to handle generation orchestration, task queues, artifact storage, and version management.
Generation capabilities are accessed through a model-service proxy, while the client depends only on a unified contract:
POST /tasks Submit a generation task -> {task_id}GET /tasks/{id} Query status and artifact URLPOST /tasks/{id}/extend Extend durationGET /assets/{id}/versions Retrieve versions and source relationships
Defining the contract first allows the client and backend to be developed in parallel and significantly reduces integration effort.
5. Perform Acceptance Testing on the Same Device
Install the new build on the same device, under the same network and account conditions, and rerun the behavior audit table item by item.
Testing on the same device removes noise caused by differences in phone models, display resolutions, and operating system versions. It is the only reliable basis for determining whether L3 fidelity has been achieved.
4. Key Requirements for Effect-Level Validation
A visually similar interface is only the entry point. The real challenge is matching observable behavior and results.
- Real execution paths: All generated artifacts must come from a real model-service proxy. Placeholder images are not acceptable.
- Complete long-running tasks: For example, a full 16-second video must play continuously without dropped frames or truncation.
- Versioning and provenance: Every generation must retain a version chain, with clear and traceable relationships between the original asset and derived results.
- Recoverable failures: Timeouts, rate limits, and network interruptions must provide clear messages and defined retry paths.
5. Cost and Common Pitfalls
The example exercise required approximately 7 hours and CNY 21. Most of the cost came from model calls and agent inference rather than human labor.
Reusable cost-reduction techniques include:
- Validate L1 and L2 first, then add L3 behavior.
- Cache repeated analysis results as specification files.
- Use a small representative screen set instead of traversing every screen.
Common failure points include:
- Failing to define the fidelity level, causing scope creep.
- Analyzing screenshots alone, which can lead to drifting control coordinates.
- Ignoring permission-denial and background-resume branches.
- Omitting task idempotency on the backend, causing duplicate submissions and corrupted data.
- Using an inconsistent acceptance environment, making results impossible to reproduce.
6. Turn the Process into a Reusable Skill Package
The workflow can be consolidated into a reusable skill package containing:
- Primitive operation definitions
- Parsing scripts
- Templates for the two audit tables
- Acceptance checklists
- Prompt constraints
With these components in place, the next replication project changes from “starting over” to a structured execution process. The skill package and reference implementation can also be hosted in a code repository, allowing a team to adapt them into its own generative product development workflow.
7. Compliance Boundaries
The legality of clean-room replication depends on several principles:
- Do not access protected implementation details.
- Do not copy trademarks or proprietary assets.
- Do not create confusion about the source or ownership of the product.
In practice, observations should be limited to publicly visible interfaces. All code and resources should be rewritten independently, with clear branding and ownership. Any form of misleading similarity should be avoided.
Technical capabilities are neutral. Awareness of legal and ethical boundaries is what makes the approach sustainable over the long term.
