Setu is a highly experimental, custom Android runtime for Windows built from scratch in C++.
Rather than running an entire Android OS inside a heavy hardware emulator or a subsystem (like WSA or QEMU), Setu runs Android application packages (.apk files) natively as a standard Win32 process. It achieves this by extracting binary XML layouts (.xml/resources.arsc), directly interpreting Dalvik bytecode (.dex), and bridging Android framework calls to native Win32 UI components in real-time.
- Dalvik Execution Engine: A custom, lightweight bytecode interpreter written in C++ that dynamically parses and executes Dalvik opcodes (from
classes.dex) line-by-line, without needing a full Java Virtual Machine. - Native UI & Rendering: Intercepts Android UI inflation (
setContentView) and renders views natively. Supports both Direct2D and Google Skia (viaSkiaCanvas) for hardware-accelerated drawing, with a real-time side-by-side A/B comparison mode for rendering validation. - Multi-DEX Support: Automatically parses and manages cross-DEX execution for modern, large Android applications containing multiple
classes*.dexfiles. - AXML & ARSC Parsing: Parses compiled Android Binary XML (AXML) and the global resource table (
resources.arsc) to resolve strings, layouts, dimensions, and control properties. - Framework Stubbing Engine: A powerful interception registry (
StubRegistry) that detects when the bytecode tries to call the standard Android Java Framework (which doesn't exist on Windows), catches it, and executes a native C++ alternative (e.g., UI callbacks,setOnClickListener,startActivity). - ConstraintLayout Solver: Integrates a native C++ Cassowary solver to accurately recreate complex Android
ConstraintLayoutconstraints.
- APK Parser (
apk_extractor/ApkExtractor.cpp): Unzips the provided.apk, extractsclasses.dex, compiled XMLs, and resource files. - Interpreter (
interpreter/Interpreter.cpp): The core execution engine. It sets up anInterpreterState(registers, stack) and steps through DEX opcodes. It handles object instantiation, virtual method invocation, and static field resolution. - Stub Registry (
interpreter/StubRegistry.cpp): Since Setu does not ship with a 2GB Java runtime, all calls toandroid.os.*,androidx.*, orjava.*are intercepted. The registry provides C++ lambda functions that simulate these calls (e.g., converting Android Intents to Win32 window transitions). - Layout Inflater (
ui/LayoutInflater.cpp): Reads the AXML layout nodes requested by the APK, extracts attributes (padding, margins, constraints), and creates the corresponding native view tree using custom rendering components. - Rendering Pipeline (
graphics/): Abstracts rendering through a unifiedCanvasinterface, allowing hot-swappable rendering backends likeDirect2DCanvasandSkiaCanvas(powered by Google Skia). - Cassowary Engine (
cassowary/): Resolves view bounds mathematically for constraint-based layouts.
Setu is built using CMake and C++17/C++20. It requires a Windows environment due to its heavy reliance on the native Win32 API.
- Prerequisites:
- Windows 10/11
- Visual Studio 2022 (with "Desktop development with C++" workload)
- CMake
- Build:
- Open the project directory in Visual Studio or use standard CMake commands.
- Wait for CMake to generate the cache.
- Select the
x64-Debugorx64-Releasebuild configuration. - Build the project target.
- Run:
- You can launch Setu via CLI (e.g.,
setu_runtime.exe --package=com.example.app) or simply double-click the executable to open an APK file picker. - The runtime will parse the APK, draw the main window, and start interpreting the
MainActivitybytecode. - Note: Ensure
framework-res.apkis available inapkresources/framework-res.apkfor standard Android resource resolution.
- You can launch Setu via CLI (e.g.,
This project is licensed under the Apache License 2.0.
Setu leverages several open-source projects and concepts:
- Android Open Source Project (AOSP): For the foundational components including ART (Android Runtime) structures,
libbase,libziparchive, andandroidfw. - Google Skia: An open source 2D graphics library which provides common APIs that work across a variety of hardware and software platforms.
- fmt: A modern, safe, and fast formatting library for C++.
- miniz: A lightweight, drop-in replacement for zlib, used for ZIP and APK extraction.
- ConstraintLayout & Cassowary: Core solver engine implementations utilized for mimicking complex Android layout structures natively on Windows.