Controlling a Real Phone with an LLM Agent: A Low-Cost Clean-Room Rebuild of a Mobile App

    A hands-on account of using an LLM agent harness plus direct device control over ADB to clean-room rebuild the core features of an AI image and video generation app. The piece lays out a five-step framework (L0–L5 fidelity grading, ADB device control, dual-channel UI parsing, spec-driven checklists, and native plus server reconstruction), the practical pitfalls encountered, and the engineering takeaways, with the rebuild completed in about seven hours at roughly 21 RMB in model-call costs. Clean-room boundaries and IP limits are stressed throughout.

    Background: When “Cloning an App” Becomes an Agent Experiment

    Last weekend I shared a project that used an LLM agent workflow (hereafter the Agent Harness) to rebuild a short-drama studio tool from scratch. A reader immediately asked: could the same approach clone a phone app?

    On impulse, I actually ran the experiment. The result: in roughly seven hours, at about 21 RMB in model-call costs, I rebuilt the core features of an AI image/video generation app. Not a static shell that merely “looks like” the original, but an effect-level rebuild that connects to a real model proxy, can extend videos, and preserves multiple output versions.

    This article breaks down the methodology, the pitfalls, and the engineering framework in full. Two premises first:

    1. This is a clean-room rebuild. I only observe the public interface and interaction results, then rewrite all code from scratch. No decompilation, no packet sniffing, no touching anyone else’s IP assets. The goal is purely technical learning and validation; the resulting product cannot be used commercially or to impersonate the original.
    2. The methodology transfers. Swap in a different target app and the same framework still holds.

    1. The First Problem: Without Decompiling, How Do You Take an App Apart?

    Many people’s first instinct is to reach for a decompiler or a dynamic hook framework. I took neither path this time, for two reasons:

    • Decompiled output is obfuscated bytecode. Feeding that to an LLM gives a very low signal-to-noise ratio and slows iteration.
    • The clean-room path is cleaner both legally and in engineering terms: look only at “what goes in, what the interface looks like, and what comes out.” That is exactly the complete picture from a product perspective.

    I borrowed the general engineering loop of “investigate → rebuild → verify → deliver” and adapted it into a five-step framework for mobile.

    2. The Five-Step Clean-Room Framework

    Step 1: Grading — Define “How Faithful the Clone Needs to Be”

    Split the rebuild into six levels, L0 through L5:

    • L0: Screenshot-level reproduction (pure UI mockup).
    • L1: Interactive static pages.
    • L2: A complete fake-data flow with full local state.
    • L3: Effect parity — connects to real model capabilities, and the output is functionally equivalent to the original (the target for this project).
    • L4/L5: Full engineering such as account systems, billing, and distributed services.

    Key principle: default to stopping at L3 and explicitly reject static fake data. Many “AI app clone” demos are really L1 screenshot fakery: they look right until you tap once and the illusion breaks. Grading first gives the agent a hard, verifiable standard.

    Step 2: Direct ADB Connection to a Real Device, Letting the Agent Take Over the Phone

    Enable USB debugging on the phone and connect it to the computer. The agent calls terminal commands directly to operate the real device:

    1. # List devices
    2. adb devices
    3. # Capture the current screen
    4. adb shell screencap -p /sdcard/s.png && adb pull /sdcard/s.png .
    5. # Export the UI control tree
    6. adb shell uiautomator dump && adb pull /sdcard/window_dump.xml .
    7. # Simulate taps and text input
    8. adb shell input tap 540 1200
    9. adb shell input text "hello"

    The point of this step is to give the LLM “hands”: it can genuinely tap, swipe, and type, instead of reasoning about a screenshot on paper.

    Step 3: Dual-Channel Parsing with Semantic Tree Plus Screenshot

    Screenshots alone make the model unreliable at precise coordinates, control hierarchy, and font sizes. The control tree alone loses all visual information. So I use dual-channel fusion:

    • uiautomator dump provides the control structure, text content, and coordinates.
    • screencap captures visual specs such as color, corner radius, spacing, and font size.

    Layering both inputs together is what lets the model produce a pixel-accurate description of the interface.

    Step 4: A Spec Checklist — Turning “Impressions” into Specifications

    Have the agent output two tables:

    • Per-screen UI diff table: for each screen, how layout, components, color values, and font sizes deviate from the original.
    • Behavior audit table: the state change before and after each interaction, for example “tap the generate button → enter loading → image produced after 3 seconds → version list +1.”

    The behavior audit table is the core evidence for L3 acceptance: functional equivalence is proven by it, not by eyeballing.

    Step 5: Native Client Plus Server Reconstruction, Verified on the Same Device

    Finally, write the native client and the server. The client implements the UI and interactions in Kotlin; the server wraps the model proxy interfaces (image generation, video extension, version management, and so on) in Python. Acceptance is done by side-by-side comparison on the same device: install both versions on one real phone, run them side by side, compare screen by screen against the UI diff table, and check each entry against the behavior audit table.

    3. Pitfalls and Lessons

    1. Unstable coordinate taps. Hard-coded coordinates drift across resolutions. Prefer locating by resource-id or text from the control tree, and use coordinates only as a fallback.
    2. Waiting for async loading. AI generation features take a long time, and the agent tends to screenshot on the loading screen and declare “failure.” Introduce a polling-wait mechanism that treats the appearance of a target UI element as the completion signal.
    3. Multi-version state management. Implicit behaviors like the version list and the original-image ownership in generation apps are the easiest to miss. The behavior audit table must cover every list-type page.
    4. Cost control. Summarize and compress the screenshot and control-tree parsing results before feeding them to the model. That keeps a single task to the tens-of-RMB range; this whole run cost about 21 RMB.

    4. Packaging and Open Source

    The whole process was eventually packaged into a reusable skill (a prompt-engineering pack) covering the grading standard, ADB command templates, and the output format conventions for parsing and auditing. The rebuilt client and server code were organized into an open-source repository for learning and further development. Using this framework to prototype a similarly shaped AI generation product is entirely feasible.

    Closing

    The biggest takeaway here is not “I cloned an app for 21 RMB.” It is validating an engineering paradigm: LLM agent + real-device control + spec-driven acceptance can compress product reverse-understanding work that traditionally takes several person-weeks into one person’s single afternoon of experimentation. For indie developers, this is a new low-cost path to validating product ideas. For teams, the “investigate → rebuild → verify → deliver” loop applies equally to competitive analysis, regression testing, and similar scenarios. Technology is neutral, but always hold the clean-room boundary and the IP line.