Skip to content

About

Android AI agent built on Pi SDK 1.7 — offline chat, Linux coding, native Media3 hardware video, AGSL GPU shaders, GPU WebView & Shizuku | 手机上的 AI Agent:Chat.、本地 Linux 编码与芯片级硬件视频/GPU 创作引擎

Topics

Resources

Stars

30 stars

Watchers

1 watching

Forks

Repository files navigation

简体中文 · English

Pi for Android

An AI agent on your phone — clean offline chat, local Linux coding, and hardware-accelerated media & GPU creation

A third-party Android client built on the official Pi SDK (@earendil-works/pi-coding-agent 1.7.0). Not affiliated with the official Pi team.

Latest Release Total Downloads CI Status GitHub Stars MIT License Android 8.0+ arm64

Download Latest APK · Install · Native Media & GPU Engine · FAQ

Pi for Android chat interface rendering Markdown tables, MathJax equations, Mermaid diagrams, and highlighted code

16-second demo of Pi for Android streaming a Markdown table, MathJax formula, code block, and queued follow-up
16-second demo: streaming layout, offline math, and message queueing (MP4 video).

Just Chat · Make It Build · Create Media & Video · Under the Hood

What It Is

  • For everyday chat: A clean, vendor-neutral mobile chat app with your own model accounts or API keys, offline Markdown/math/diagram rendering, Android System Share Target (share photos, videos, audio, PDFs, or text straight from any app into chat), and local JSONL history.
  • When you need code & files: A bundled Ubuntu 24.04 ARM64 Linux environment with a multi-tab PTY terminal and a full-format native workspace (word-level diffs, O(1) directory browsing, smart UTF-8/UTF-16/GB18030 detection, and built-in PDF / SVG / ZIP / HTML / ExoPlayer media viewers).
  • When you want AI to edit videos, render code animations, or drive a real browser: An opt-in Android-Native Media, GPU & Hardware Browser Engine powered directly by your phone's SoC hardware codecs (Jetpack Media3 1.11), System GPU WebView + VirtualDisplay, Android 13+ AGSL GPU shaders, MediaStore, and official Shizuku UserService — off by default with 0 prompt tokens.
  • Pi's minimalist philosophy, full upstream compatibility: Runs the official @earendil-works/pi-coding-agent 1.7.0 SDK directly — deliberately does not bundle opinionated workflows like sub-agents or built-in web search. Full compatibility with upstream Pi extensions, skills, themes, MCP, and ~/.pi layouts: whenever you need extra capabilities, install a community package or simply ask the AI to install or build one for you.

Clean, Offline Reading

You get offline rendering for Markdown, tables, MathJax 4 equations, Mermaid 12 diagrams, and syntax-highlighted code, with steady streaming that avoids scroll jitter. Long replies open into a dedicated Copy Studio for free text selection or block-by-block copying, and rendered video/audio outputs open right inside an in-app ExoPlayer preview.

Offline MathJax equations, Mermaid diagrams, syntax-highlighted code, and full-screen Copy Studio

Your Models, Your History

Sign in directly with OAuth subscription accounts, enter your own API keys, or point to any self-hosted OpenAI/Anthropic/Gemini-compatible gateway. One-tap Fetch Models automatically preserves upstream reasoning_levels / thinkingLevelMap (supporting the full 7-tier off through xhigh / max range), with a visual per-model thinking-tier editor, /tree session branching, and local file storage.

Model and provider picker, thinking depth and context ring controls, and /tree session branching

Hands-On When Needed

A ready-to-use local Linux environment (Ubuntu 24.04 ARM64, Node.js, Git, ripgrep, fd) is bundled inside the app. Pick any workspace folder so the agent can inspect files, edit code with word-level diffs, and run commands while you jump into the built-in multi-tab PTY terminal anytime.

The modernized Workspace & File Viewer includes:

  • Fast O(1) directory listing, automatic UTF-8 / UTF-16 / GB18030 encoding detection, chunked streaming for large files, read-only Find, word-wrap toggle, and line-jump highlighting.
  • Built-in native previews for PDF (PdfRenderer), SVG (AndroidSVG zoom + light/dark canvas), ZIP / JAR / APK (tree inspection + one-tap extract), HTML (same-origin WebViewAssetLoader + Source/Preview toggle), and Video / Audio (in-app ExoPlayer).
  • On-demand Session Changes bottom sheet with expandable inline diffs — never cluttering directory navigation.

Tool cards with word-level inline diffs, workspace file explorer, and built-in multi-tab PTY terminal

Native Android Media, GPU & Browser Engine

Most mobile AI coding setups run everything inside a Linux container (PRoot + CPU ffmpeg + software headless Chromium). On a phone, that means slow software video encoding, thermal throttling, broken GPU sandboxes, huge Chromium downloads, and zero access to the system gallery.

Pi for Android flips the architecture: the Linux container handles code, data, scripts, and CLI tools, while a secure loopback bridge (builtin:pi-android-bridge) hands heavy media, graphics, and web tasks straight to Android's native hardware pipelines.

What You Can Build & Create

Capability Group Tools What It Does in Practice
Media Library media_library Browse system MediaStore albums, inspect media metadata, extract smart thumbnails or frame-exact keyframes (Media3 FrameExtractor, optionally attached directly to multimodal vision via inlineImage), read/strip GPS & camera EXIF tags, and save finished exports to Gallery.
Hardware Video Engine video_compose Jetpack Media3 1.11 Transformer hardware video editing: multi-clip trim/concat/transitions, still-to-video, piecewise speed ramps (speedSegments), multi-track PiP & split-screen, styled subtitles / progress bars / timecodes, .cube 3D LUT / HaldCLUT color grading, custom GLSL ES shaders, BGM mixing with keyframed ducking & silence skipping (skipSilence), and SoC hardware H.264 / HEVC encoding (or fast remux).
GPU & Web Renderer web_browser, web_render, shader_render (Pi 1.7.0 deferred) Persistent GPU WebView Browser: multi-session, isolated ProfileStore cookies, async JS eval, click/type/scroll, network capture, ad/media blocking, full-page stitched screenshots (inlineImage), and native vector PDF export (PdfDocument).
Code-to-Video (web_render): mobile Remotion / Manim workflow — write HTML / CSS / SVG / Canvas2D / Three.js / ECharts animations, render deterministically on a GPU VirtualDisplay, and encode straight to hardware CFR MP4.
GPU Shaders (shader_render): Android 13+ AGSL RuntimeShader with multi-input textures (iChannel0..3), ImageDecoder (HEIF/AVIF/HDR), and zero-copy EGL → MediaCodec video export.
Shizuku Device Shell android_shizuku Official Shizuku AIDL UserService (Sui-compatible) for ADB (uid=2000) or Root shell commands over OS pipes (up to 4 MiB streaming stdout/stderr), plus privileged package listing and getprop queries.

Zero-token & background-safe by design: All four groups are disabled by default (0 prompt tokens) and request no permissions until you opt in. GPU & browser tools use Pi 1.7.0 deferred schemas so they stay out of context until needed. Long hardware renders automatically run under a foreground service + WakeLock with live progress notifications (including Android 16 Notification.ProgressStyle) and one-tap Cancel, and finished videos play directly inside Chat via ExoPlayer.

Why Native Android Bridge Beats PRoot + Headless Chromium + FFmpeg

Dimension Traditional PRoot + Headless Chromium + FFmpeg Pi for Android Native Bridge + Linux Hybrid
Video encoding & filters CPU-only software libx264/libx265 under ptrace syscall overhead — slow, hot, heavy battery drain SoC hardware MediaCodec via Media3 Transformer: hardware decode → OpenGL ES GPU filters/LUT/overlays → hardware H.264/HEVC encode with zero CPU pixel copy
Code-to-video & WebGL Requires installing 300–600 MB Chromium in PRoot with --no-sandbox --disable-gpu --disable-dev-shm-usage; WebGL falls back to CPU SwiftShader Reuses Android System WebView on an Activity-hosted GPU VirtualDisplay — real WebGL2/Canvas2D hardware acceleration, system CJK/Emoji fonts, zero extra binary download
Procedural graphics & shaders CPU pixel loops (Python/Pillow/ImageMagick) Android 13+ AGSL RuntimeShader directly on mobile GPU + EGL Surface Blitter feeding hardware MediaCodec
Gallery, vision & playback Blind sandboxed container; manual file copying; no native EXIF/MediaStore or inline player Direct MediaStore + ExifInterface + Media3 FrameExtractor (auto-attaches keyframes to vision models) + in-app ExoPlayer preview
Background stability Background PRoot jobs easily throttled or killed by Android LMK; lingering Chromium zombie processes Foreground Service + WakeLock + live progress notification (Android 16 ProgressStyle) + clean job cancellation and memory trimming
Best of both worlds Linux only — trapped inside container limits Linux + Native Android together: run Python/Node/Git in Linux to generate data, scripts, subtitles, or Three.js scenes, then hand off to Android hardware for fast GPU/codec rendering

Minimalist Core, Full Pi Ecosystem

Following Pi's minimalist design philosophy, the app keeps its core lean and does not bundle sub-agents, built-in web search, or rigid default workflows. Because it runs the official Pi SDK directly, it stays 100% compatible with upstream extensions, skills, prompt templates, MCP servers, and Code Mode — whenever you want sub-agents, web search, or any custom workflow, install an upstream package or simply ask the AI to install or build one for you.

Extensions and skills management alongside MCP servers and Code Mode orchestration

Desktop TUI Extensions on Mobile

Many desktop Pi extensions draw text-based panels, progress bars, or status widgets inside a terminal. Pi for Android maps them onto your phone through a Virtual TUI with an 80-column desktop floor (smooth horizontal scroll with edge fade on narrow screens), touch scrolling, clickable links, and extracted quick actions.

Mobile Virtual TUI cell grid panel and floating extension widget above the composer

Comparison

Aspect Cloud Chat Wrappers Termux + CLI pi Pi for Android
Reading & formatting Native UI; math/diagram support varies by vendor Plain terminal text on a narrow screen Native UI with offline MathJax 4, Mermaid 12, and code
Local files & shell Typically file uploads only; no local runtime Full local environment; manual setup required Bundled Linux runtime, native PDF/SVG/ZIP/HTML/media viewer & PTY terminal
Models & history Accounts and chat logs usually cloud-hosted Local storage and bring-your-own models Local storage; OAuth, API keys, /models discovery & 7-tier thinking map
Video, GPU & browser Cloud-only or unsupported Slow CPU FFmpeg & fragile PRoot Chromium Native Media3 1.11, GPU WebView, AGSL shaders, MediaStore & Shizuku
Desktop Pi TUI extensions Not compatible with Pi extensions Native terminal display; awkward with soft keyboards Virtual TUI projection with 80-col floor, touch scroll & action chips

Installation

Requirements: Android 8.0 (API 26) or newer on an arm64-v8a device (Android 13+ recommended for AGSL GPU shaders). No Root and no Termux required.

  1. Download pi-android-*-sideload28-arm64.apk from GitHub Releases and install it.
  2. Open the app and wait briefly while the first launch unpacks the bundled runtime.
  3. Open Settings → Models & Providers, sign in via OAuth, enter an API key, or fetch models from your custom gateway, and start chatting.
  4. (Optional) Enable any native media/GPU/Shizuku group you need in Settings → Device Capabilities, or pick a project folder from the top bar menu when you want the agent to work on code.

Choosing a build: pick sideload28 for everyday use (it pins targetSdk 28 so Android 10+ allows executing the unpacked runtime reliably); modern36 is provided for testing targetSdk 36 behavior. Future updates install in place via Settings → App Updates without wiping your conversations or tools.

Frequently Asked Questions

1. Do I need Root or Linux knowledge?

No. If you only want to chat, share media, or use the video/GPU engine, you never touch a terminal or Linux commands. Picking a project folder is only needed when you ask the agent to read or modify code files.

2. Can I share photos, videos, or files from other apps directly to Pi?

Yes. Pi registers as an Android System Share Target (ACTION_SEND / ACTION_SEND_MULTIPLE) and uses Android's PickVisualMedia photo & video picker. Images are attached cleanly to vision prompts, while videos, audio, PDFs, and documents are staged into the active workspace so the agent (or the native media engine) can inspect or process them right away.

3. Why aren't web search or sub-agents built in?

Pi for Android follows Pi's minimalist design philosophy: it deliberately does not bundle sub-agents, built-in web search, or bloated default workflows, keeping the core lean with zero wasted context. Because it is 100% compatible with the upstream Pi ecosystem, whenever you need web search, sub-agents, or any custom capability, simply install an upstream Pi extension / skill / MCP — or ask the AI right inside chat to find, install, or write one for you (and if you need to inspect live JS-heavy web pages, you can also enable the opt-in web_browser hardware WebView).

4. Where are chats stored, and are they uploaded anywhere?

Sessions (JSONL files), settings, and credentials stay inside the app's local storage (~/.pi/agent/). There is no developer-hosted backend server; prompts go directly from your phone to the model providers or MCP servers you configure.

5. How much storage space does it need?

The APK is around 150 MB (bundling Ubuntu 24.04 ARM64 base, Node.js, Git, ripgrep, fd, and offline math/diagram engines). After first-launch extraction, plan for roughly 1 GB of free space to leave room for unpacked tools, package caches, and rendered media outputs.

6. How do I upgrade without losing data?

Use Settings → App Updates inside the app or install a newer APK of the same build variant (such as sideload28) over the existing installation. Releases share a fixed sideload signing key and only replace changed runtime bundles by checksum, preserving your sessions, settings, workspaces, and installed container packages.

7. Is it compatible with desktop Pi configurations?

Yes. Because it runs the official @earendil-works/pi-coding-agent 1.7.0 SDK directly, ~/.pi/agent/, project .pi/ folders, models.json (including thinkingLevelMap), theme JSON files, JSONL sessions, skills, and extensions follow desktop conventions.

8. How should I choose between PRoot, Proroot, and TAWCROOT?

Stick with the default PRoot for broad device compatibility. Proroot (closed-source binary) and TAWCROOT (open-source single-process seccomp backend built from source in CI) are experimental options aimed at lower syscall overhead; switching runs an automated compatibility probe and falls back to PRoot if a check fails. See docs/runtime-engines.md.

9. Are the native device capabilities safe and token-efficient?

All four capability groups (Media Library, Hardware Video Engine, GPU & Web Renderer, Shizuku Device Shell) are turned off by default and inject zero tool definitions into your prompts while off. They can also be paused per session, communicate only over a 127.0.0.1 loopback socket authenticated by a per-session 256-bit Bearer token with write-ahead JSONL audit logging, and require explicit opt-in permissions (Android 14+ partial photo selection is supported).

10. What is the relationship to the official Pi project?

Pi for Android is an independent, community-maintained third-party Android client built on top of the published @earendil-works/pi-coding-agent SDK. It is not produced or endorsed by the official Pi team.

11. Why is it not on Google Play?

The recommended sideload28 build pins targetSdk 28 so Android 10+ allows executing unpacked Linux binaries from app storage, which does not meet Google Play's target API requirement, and uses a public fixed sideload key in the repository for seamless in-place updates. The modern36 variant tracks targetSdk 36 compatibility work.

Data, Permissions, and Risks

  • Data flow: The app ships no analytics or ad SDKs. Network traffic goes strictly to the model endpoints, MCP servers, and websites you explicitly instruct it to visit, plus manual update checks against GitHub Releases.
  • Core permissions: INTERNET connects to your configured providers; FOREGROUND_SERVICE (specialUse) + WAKE_LOCK + POST_NOTIFICATIONS keep long agent turns and background hardware video renders running with live progress notifications; MANAGE_EXTERNAL_STORAGE is requested only when you pick an external device folder as a workspace because containers bind-mount real filesystem paths; usesCleartextTraffic allows cleartext HTTP for local loopback services and Markdown http:// images.
  • Optional native capability permissions & risks:
    • Media Library requests READ_MEDIA_IMAGES / READ_MEDIA_VIDEO / READ_MEDIA_AUDIO (with Android 14+ READ_MEDIA_VISUAL_USER_SELECTED partial access support, or READ_EXTERNAL_STORAGE on Android ≤ 12) only when you grant it in Settings → Device Capabilities.
    • Hardware Video Engine and GPU & Web Renderer run directly on workspace files and Android hardware codecs/WebView without requesting extra runtime permissions.
    • Shizuku Device Shell connects through official Shizuku UserService only if you install, start, and authorize Shizuku yourself. Enabling Shizuku grants the agent ADB (uid=2000) or Root shell execution; prompt injection or model mistakes could run unintended commands, so enable it only when needed and pause it per session when done.

For Developers

Architecture, protocol docs, CI guards, building from source, and asset regeneration

Architecture Overview

flowchart TB
    A["Android Native UI (Kotlin · Jetpack Compose)"]
    B["Offline Render Pipeline (GFM · MathJax 4 · Mermaid 12) · Virtual TUI · PTY Terminal · Native Viewers (PDF/SVG/ZIP/ExoPlayer)"]
    C["Typed JSONL Frame Protocol (seq · epoch · backpressure)"]
    D["Node.js SDK Host (host.bundle.mjs + builtin:pi-android-bridge)"]
    E["Official @earendil-works/pi-coding-agent 1.7.0 SDK"]
    F["Container Runtimes (PRoot · Proroot · TAWCROOT) + Ubuntu 24.04 ARM64 / Node 24"]
    G["Android Native Hardware Bridge (127.0.0.1 · Bearer Token · Audit Log)\nMedia3 1.11 Transformer · AGSL/EGL MediaCodec · GPU WebView VirtualDisplay · MediaStore · Shizuku UserService"]

    A --> B --> C <--> D --> E
    D --> F
    D <--> G
Loading
  • Technical documentation: Architecture · Wire Protocol · SDK Upgrading · Runtime Engines · AGENTS.md
  • Automated CI and cold-start guards: Every push runs 6 GitHub Actions jobs (tawcroot NDK build, SDK Host contract and runtime suite including cold-start import-audit, Static safety guards including cold-start guards and i18n checks, JVM unit tests, APK modern36, and APK sideload28).

Building from Source

git clone https://github.com/heikeyangle-code/pi-android.git
cd pi-android

# 1. Run SDK host checks, startup guards, and unit tests
node tools/sdk-host/contract.mjs
node tools/sdk-host/test.mjs
node tools/check-startup-perf.mjs
./gradlew :protocol:test :app:testDebugUnitTest

# 2. Fetch runtime bundles and assemble the Release APK
node tools/fetch-runtime.mjs
./gradlew :app:assembleRelease

Regenerating README Assets

All static galleries (WebP), animated demos (GIF), and videos (MP4) in this README are generated reproducibly from code using the repository's own bundled fonts and offline MathJax 4 / Mermaid 12 engines:

# Requires Python 3, Playwright, Chromium, ffmpeg, and cwebp
python3 tools/readme-assets/render.py

Generator sources live in tools/readme-assets/ and write to docs/assets/.

Community and Feedback

Contributing

Issues and pull requests are welcome. Before submitting changes, please read AGENTS.md for cold-start performance guards, rendering rules, and bilingual requirements. If you edit anything under app/src/main/assets/guest/sdk-host/ or app/src/main/assets/pi-extensions/pi-android-bridge/, run node tools/sdk-host/build-bundle.mjs and verify that static guards and tests pass.

License and Acknowledgements

Released under the MIT License. Third-party components bundled inside the APK are distributed under their respective upstream licenses; see Settings → Open-Source Licenses inside the app or app/src/main/assets/licenses/ for the full manifest and license texts.

Acknowledgements:

  • @earendil-works/pi-coding-agent: Core agent session, tools, extensions, and MCP runtime.
  • AndroidX Jetpack Media3 & AndroidX WebKit: Hardware video composition (Transformer), GPU effects (Effect), playback (ExoPlayer), frame/metadata inspection (Inspector), ProfileStore, and WebViewAssetLoader.
  • Termux: terminal-emulator, terminal-view, proot, and libandroid-shmem.
  • proroot: Optional experimental container runtime (proprietary component redistributed unmodified; see proroot-license.txt).
  • wmww/tawc: Experimental single-process seccomp container backend tawcroot (MIT).
  • Offline rendering engines: Mermaid and MathJax for vector diagrams and math equations.
  • Android rendering and system libraries: JetBrains Markdown, AndroidSVG, jsoup, SnakeYAML, and Shizuku API.
  • Bundled fonts: IBM Plex Sans SC, JetBrains Mono, Geist Mono, Source Han Serif CN, and LXGW WenKai.

About

Android AI agent built on Pi SDK 1.7 — offline chat, Linux coding, native Media3 hardware video, AGSL GPU shaders, GPU WebView & Shizuku | 手机上的 AI Agent:Chat.、本地 Linux 编码与芯片级硬件视频/GPU 创作引擎

Topics

Resources

Stars

30 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages