Clean-Room App Reconstruction with LLM Agents: A Complete Practical Guide
How to faithfully recreate a mobile app using LLM agents without decompilation or packet sniffing. This guide walks through a clean-room reconstruction workflow—grading the target, controlling a real device via ADB, dual-channel UI parsing, structured specifications, and same-device validation—with lessons on cost, pitfalls, and a reusable methodology for rebuilding AI generation apps.
Background: From Recreating a Studio to Recreating a Mobile App
Last weekend I shared a practice: using an LLM agent orchestration framework with a “investigate → rebuild → verify → deliver” workflow to recreate a short-drama production studio from scratch. Comments immediately asked: can you recreate a mobile app?
I picked a target—an AI generation product with features including image generation, video generation, video editing, and video extension. The final result: not only a high-fidelity UI, but a one-to-one restoration of the functional logic, including real LLM proxy calls, full-length playback of a 16-second extended video, multi-version retention, and original-image attribution tracking.
The entire process used no decompilation tools and no traffic sniffing. Instead, it took a cleaner, more compliant route: clean-room reconstruction.
The takeaway up front: I’ve distilled this methodology into a reusable skill pack, open-sourced alongside the reconstructed native client and server code. Readers can use it for learning or secondary development—building a similar AI generation product is entirely feasible.
Core Methodology: Why Clean-Room Reconstruction?
Faced with “recreate a mobile app,” many developers’ first instinct is to decompile the APK or sniff the API traffic. But both paths have obvious problems:
- Legal and compliance risk: decompiling bytecode or decrypting private protocols easily crosses intellectual property red lines;
- High information noise: commercial apps are obfuscated and hardened, making decompiled output extremely inefficient to read;
- Not verifiable: static analysis tells you “what the code looks like,” not “what the user sees and what happens when they tap.”
Clean-room reconstruction takes a fundamentally different approach: observe only the publicly visible UI and interaction results, then rewrite all native code from scratch. The observer operates the app like an ordinary user, recording every screen’s layout, colors, and interaction feedback, then uses these “behavioral specifications” to reimplement it. This is legally safer and more focused in engineering terms—because the acceptance criterion is “identical side-by-side on the same device,” not “identical code structure.”
The Five-Step Clean-Room Framework
The whole process can be abstracted into five stages:
- Grading: split the reconstruction target into levels L0–L5. L0 is visual-only restoration; L3 is behavioral equivalence (the default baseline, rejecting static fake data); L5 is full functional parity;
- Real-device connection: enable USB debugging on the phone, connect to a computer, and let the agent take over the device via terminal commands;
- UI parsing: extract information through a dual channel of control structure plus screenshots;
- Specification documents: produce structured difference tables and behavior audit tables;
- Rebuild and same-device validation: write the native client and server, install on the same device, and run A/B comparison.
Let’s go through each step.
Step 1: Grading—Decide “How Far to Recreate” First
The biggest pitfall in reconstruction is starting without acceptance criteria. Grade the target first:
- L0 Visual parity: screenshot comparison; restore colors, corner radii, font sizes, and spacing;
- L1 Interaction parity: identical behavior for taps, swipes, and form validation;
- L2 Flow parity: complete user paths (login → generate → view → share) work end to end;
- L3 Behavioral parity: core features call real backend capabilities and produce real results—no “fake loading” or “fake data”;
- L4–L5: deep parity of account systems, billing, multi-device sync, and so on.
This practice defaulted to L3: all generation features had to make real LLM proxy calls and return real output—no static mocks accepted. This rule matters enormously. Many “recreation demos” die on fake data: they look right but fall apart the moment you actually use them.
Step 2: ADB Real-Device Connection—Let the Agent “Get Hands-On”
Reconstruction starts with “seeing.” Letting the agent directly operate a real device is the key infrastructure of the whole approach:
# Connect the phone (USB debugging enabled) to the computeradb devices # Confirm the device is onlineadb shell uiautomator dump /sdcard/ui.xml # Export the current UI control treeadb shell screencap -p /sdcard/screen.png # Take a screenshotadb pull /sdcard/ui.xml . && adb pull /sdcard/screen.png .
The agent framework can loop: dump → screenshot → analyze → execute input events (adb shell input tap/swipe/text) → dump again, forming an automated “exploration agent.” This is essentially a perceive-decide-act loop—the agent is effectively a tireless QA engineer.
Step 3: Semantic Tree + Screenshots—Dual-Channel UI Parsing
A single information source is never enough; you need dual-channel cross-validation:
- Semantic tree (uiautomator dump): provides the control hierarchy, types, resource-ids, text, and coordinate bounds. Best for restoring “structure”;
- Screenshots: provide pixel-level truth—gradients, shadows, icons, and intermediate frames of animations. Best for restoring “styling.”
Several typical pitfalls I hit in practice:
- WebView pages may expose only coarse-grained nodes in the control tree. In that case, rely primarily on visual analysis of screenshots, using a vision model to estimate layout parameters;
- Animations can’t be reconstructed from single-frame screenshots—record the screen (
adb shell screenrecord) and analyze frame by frame; - Dark mode and different screen densities change styling. Freeze your test conditions, or the side-by-side validation will produce “false differences.”
Step 4: Specification Documents—Turn “What You Saw” into “What’s Executable”
Exploration produces massive raw data; feeding it directly into code generation goes off the rails. The key is converging it into two structured documents:
Per-screen UI difference table: one row per screen, recording layout structure, component list, color values, font sizes, spacing, icon assets, and empty/loading/error states.
Behavior audit table: records the state transitions of every interaction, like:
| Trigger | Precondition | Expected Feedback | Post-state |
|---|---|---|---|
| Tap “Generate Video” | Form filled | Show progress page, poll the task | Task completes, navigate to result page |
| Tap “Extend Video” | 16-second clip exists | Call backend extension task | Return extended version, old version retained |
These two tables are the “blueprints” for code generation. Experience says: the more detailed the audit table, the higher the first-pass success rate of the rewrite. Especially versioning logic (multi-version retention, original-image attribution)—if it isn’t written down clearly, rework is inevitable.
Step 5: Rebuild Native Client + Server, Validate on the Same Device
The final step is the actual coding:
- Native client: rewrite the Android client in Kotlin, screen by screen following the difference table, UI layer first;
- Server: build a lightweight backend in Python, wired to an LLM proxy for image/video generation and video extension, with asynchronous task handling and version storage;
- Same-device validation: install the recreated app on the same device, operate it side by side with (or alternating with) the original app, compare screenshots screen by screen, and verify each entry in the audit table.
For validation, automation is recommended: write a script that drives two devices (or the same device in alternating turns), takes screenshots after each step, runs similarity comparison with a vision model, and outputs a difference report. L3 validation focuses on “outputs are real and usable”—the generated images are real images, and the extended video genuinely plays end to end.
Cost and Lessons Learned
The whole run took about 7 hours, with a total LLM cost of roughly 21 RMB (~$3). The pitfalls, distilled into three:
- Don’t try to generate all the code at once—iterate incrementally, with each screen as the smallest delivery unit;
- State management is the deep water of reconstruction: visuals are easiest, interactions next, and cross-screen state (version attribution, task polling) is hardest. The audit table must cover it;
- Freeze the validation environment: same device, same OS version, same network conditions—otherwise the comparison results aren’t trustworthy.
Closing Thoughts
This clean-room framework—“grading → real-device connection → dual-channel parsing → specification documents → rebuild and validate”—essentially moves app reverse engineering from “code-level cracking” to “behavior-level observation”: both compliant and efficient. The accompanying open-source project includes the complete reconstruction output and server code; feel free to download it for learning or secondary development. Building your own AI generation product on this foundation is entirely achievable. Good luck shipping.
