Skip to content
ComzvyPublic

About

Krita 5.3.1.1 Android Smartphone UI Mod, Background Foreground Service, and MCP Server for Antigravity

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

Krita Smartphone Mod & Krita MCP for Antigravity

A modified build of Krita 5.3.1.1 (arm64-v8a) tailored for smartphone screens, paired with an embedded Krita MCP Server (Blender-MCP architecture) for Antigravity.

Download Prebuilt APK

Download the signed, ready-to-install APK from GitHub Releases:

  • Release: v5.3.1.1-smartphone-mcp
  • File: krita-arm64-v8a-5.3.1.1-smartphone-mcp-signed.apk (159.1 MB)
  • SHA-256: d65a4939f79f74ae9f68f82b83832a1f3a92d5d635f71a874030b124e30643f8

Note

The APK is distributed via GitHub Releases because it exceeds GitHub's 100 MB per-file Git object limit.


Smartphone UI & Background Features

  1. Smartphone Screen & Background Manifest (scripts/patch_manifest.py)
    • Enables android:smallScreens="true" and android:normalScreens="true".
    • Enables android:name="android.app.background_running" android:value="true" and sets QT_BLOCK_EVENT_LOOPS_WHEN_SUSPENDED=0 so Krita's Qt event loop stays alive when Antigravity sends MCP commands in the background.
    • Declares FOREGROUND_SERVICE_SPECIAL_USE, POST_NOTIFICATIONS, WAKE_LOCK, and org.krita.android.McpForegroundService.
  2. Fractional HiDPI Scaling (PassThrough, default 1.55x)
    • Prevents Qt5 on Android from rounding 2.625x (420dpi) up to 3.0x on 1080x2400 phones (360x800 logical px). With 1.55x, the workspace expands to ~697x1470 (portrait) / ~1470x697 (landscape).
    • Configurable at runtime via control_ui_and_view (phone_scale) or /sdcard/Android/data/org.krita/files/krita_phone_scale.txt.
  3. Responsive Smartphone UI & Quick-Bar
    • Automatically clamps QDialog windows inside the available screen bounds.
    • Tabifies dockers cleanly to the Bottom (portrait) or Right (landscape) with compact 18x18 toolbar icons.
    • Adds a touch-friendly Smartphone Quick-Bar: Dockers, Canvas, PhoneFit, Undo, Redo, FitZoom, Save, and MCP:9876 (with live Foreground Service indicator).
  4. Background & Lockscreen Foreground Service (classes2.dex + classes.dex patch)
    • org.krita.android.McpForegroundService (specialUse, android:permission="android.permission.DUMP") keeps a persistent "Krita MCP Active" notification and a continuous PARTIAL_WAKE_LOCK so Android does not freeze Krita while minimized or while the screen is off/locked.
    • scripts/patch_dex.py surgically NOPs MainActivity.onStart()'s unguarded startService(DocumentSaverService) call in classes.dex to prevent BackgroundServiceStartNotAllowedException during cold-starts behind the lockscreen.
    • Includes a headless QtLayout reflection kickstart (ensureQtStarted()) + ACTION_USER_PRESENT unlock listener, and defers Window::addView() while the screen is off or locked (!isScreenReadyForView()), attaching views safely 350ms after unlock/resume.
    • get_krita_info reports wake_lock_held, battery_optimization_ignored, screen_interactive, and device_locked, and krita_mcp_server.py auto-applies Doze/AppOps exemptions and starts McpForegroundService first when rish is available.
    • Validates QPointer<KisDocument> strongref counts before every document access, serializes McpEvent dispatch to prevent nested-event-loop re-entrancy, and provides an idempotent close_document tool.
    • save_document enables batchmode(true) and saves raster formats (.png, .jpg, .webp, .bmp) directly from doc->projection() without blocking GUI dialogs.

Krita MCP Architecture (20 Tools)

  • Embedded Native Bridge (native/krita_phone_mcp_bridge.cpp → libdummytrivialinterface_arm64-v8a.so): Runs inside org.krita, listens on 127.0.0.1:9876 with heap-refcounted std::shared_ptr<McpRequest> synchronization, serialized non-reentrant Qt dispatch, live QPointer document lifecycle validation, lock-free <1ms TCP ping, batch_commands, SVG Bezier path & blend_mode support in draw_shapes, and libkritalibkis / QJSEngine integration.
  • MCP Server (krita_mcp_server.py): Stdio JSON-RPC 2.0 server (plus --cli mode) with a persistent keep-alive TCP client, adaptive per-tool timeouts (20s–120s), and optional auto-launch via Shizuku (rish) when Krita is closed. Once Krita is open, all MCP tools run without Shizuku.

Available Tools

Category Tools
Status & Inspection get_krita_info, get_document_info, get_layer_info, get_canvas_screenshot, list_resources
Document & Layers create_document, open_document, save_document, close_document, create_layer, modify_layer
Drawing & Vectors set_brush_and_colors, paint_strokes, draw_shapes (fills, gradients, rects, ellipses, lines, polygons, SVG path, blend_mode, wrapped aligned text), add_vector_svg
Filters & Selection apply_filter, manage_selection
UI, Batch & Scripting control_ui_and_view, batch_commands, execute_krita_code

Antigravity Configuration (~/.gemini/config/mcp_config.json)

{
  "mcpServers": {
    "krita": {
      "command": "python3",
      "args": ["/storage/emulated/0/Documents/Mod/krita-mcp/krita_mcp_server.py"]
    }
  }
}

Sample Artwork Generated via Krita MCP

JoJo vs DIO Manga Scene (scripts/draw_jojo_vs_dio.py) Stickman Demo
JoJo vs DIO Stickman Demo

Project Layout

  • android/org/krita/android/McpForegroundService.java: specialUse Foreground Service + continuous PARTIAL_WAKE_LOCK + headless ImageReader surface feeder & unlock handoff for background, Doze, and lockscreen reliability.
  • native/krita_phone_mcp_bridge.cpp: Native C++ bridge (libdummytrivialinterface_arm64-v8a.so) for smartphone scaling, Quick-Bar, dialog clamping, and the 127.0.0.1:9876 MCP TCP server.
  • scripts/patch_manifest.py: Binary AndroidManifest.xml patcher (smallScreens, normalScreens, background_running, FGS + WAKE_LOCK + REQUEST_IGNORE_BATTERY_OPTIMIZATIONS permissions/service).
  • scripts/patch_dex.py: Surgical classes.dex patcher preventing MainActivity.onStart() BackgroundServiceStartNotAllowedException and bypassing QtNative.m_activityPaused stalls in runAction() / runPendingCppRunnablesOnAndroidThread() for cold-starts behind the lockscreen.
  • scripts/build_apk.py: Repackages, zipaligns, and signs the APK (classes.dex, classes2.dex, AndroidManifest.xml, libdummytrivialinterface_arm64-v8a.so).
  • scripts/build_all.py: One-command build pipeline (manifest + classes2.dex + native C++ + 0-unresolved-symbol check + APK signing).
  • scripts/draw_jojo_vs_dio.py: Demo script rendering the JoJo vs DIO manga confrontation via Krita MCP.
  • krita_mcp_server.py: JSON-RPC 2.0 MCP server (stdio + --cli) exposing 20 tools to Antigravity.

Rebuild From Source

python3 scripts/build_all.py

About

Krita 5.3.1.1 Android Smartphone UI Mod, Background Foreground Service, and MCP Server for Antigravity

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages