Compiles, packages, and signs Android APKs directly on Android via Termux using native ART execution.
  • Python 81.3%
  • Java 18.7%
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
Farhan Ali c42d47236c feat: add incremental compilation caching
Cache SHA-256 hashes of build inputs and skip unchanged resource, Java, and DEX compilation stages. Use buffered file reads and include generated R.java in Java source tracking.
2026-09-07 20:29:12 +05:00
src feat: add incremental compilation caching 2026-09-07 20:29:12 +05:00
tools feat(compiler): replace legacy dx with D8 dexer and persist patch script 2026-09-02 16:01:21 +05:00
.gitignore chore: ignore .flock files and remove unnecessary Test entry from .gitignore 2026-09-03 12:50:23 +05:00
.python-version initial commit 2026-08-14 08:39:59 +05:00
LICENSE docs: update README for D8 dexer and Java 16 pipeline, add MIT license 2026-09-02 16:13:59 +05:00
pyproject.toml fix: lower Python requirement to 3.7 (i forgor) 2026-09-03 11:00:08 +05:00
README.md feat: add incremental compilation caching 2026-09-07 20:29:12 +05:00
uv.lock fix: lower Python requirement to 3.7 (i forgor) 2026-09-03 11:00:08 +05:00

kosei

Python Version License Platform

Compiles, packages, and signs Android APKs directly on Android devices via Termux. No host machine, Android Studio, or desktop SDK installation required.

Build Pipeline

aapt2 compile     ->  compile res/ into .flat files
aapt2 link        ->  link .flat + AndroidManifest.xml -> .apk + R.java
ecj.jar (3.27.0)  ->  compile .java + R.java -> .class files (Java 16)
d8.dex            ->  desugar and convert .class -> classes.dex
zipfile           ->  inject classes.dex into the .apk
apksigner.dex     ->  sign the .apk with debug.pk8 and debug.x509.pem

Requirements

  • Python >= 3.7
  • Termux with aapt2 in $PATH
  • ART at /apex/com.android.art/bin/dalvikvm or /system/bin/dalvikvm
  • Bundled runtime binaries in src/data/

Installation

Create a virtual environment and install in editable mode using uv:

uv venv
uv pip install -e .

Usage

Create a project with default package (com.example.hello):

kosei new Hello

Create a project with custom package and directory:

kosei new Hello -p com.mycompany.hello -d ./projects

Build project in current directory:

kosei build

Build project in specified directory:

kosei build ./projects/Hello

Clean build artifacts:

kosei clean ./projects/Hello

Alternative Python module execution:

python -m kosei new Hello
python -m kosei build

Build Outputs:

  • build/[AppName].apk — Unsigned intermediate package inside the project build directory
  • [AppName].apk — v1/v2/v3 signed APK ready for installation

data Directory

All runtime binaries live under src/data/ and execute natively on Android's dalvikvm engine.

File Description Purpose
android.jar Android framework resource stubs Passed to aapt2 link -I to resolve @android: attribute references and generate R.java
android.classes.jar Android framework class definitions Passed to ecj.jar via -cp so the Java compiler resolves android.* imports
ecj.jar Eclipse Java Compiler 3.27.0 (patched for Dalvik) Invoked via dalvikvm -cp ecj.jar org.eclipse.jdt.internal.compiler.batch.Main to compile Java source into .class files (up to Java 16)
d8.dex Google D8 Dexer packaged as .dex Invoked via dalvikvm -cp d8.dex com.android.tools.r8.D8 to desugar and convert .class bytecode into classes.dex
apksigner.dex Android APK Signer tool packaged as .dex Invoked via dalvikvm -cp apksigner.dex com.android.apksigner.ApkSignerTool to apply v1, v2, and v3 signatures
debug.pk8 PKCS8 private key for debug signing Provided to apksigner via --key to sign debug builds
debug.x509.pem X.509 certificate for debug signing Provided to apksigner via --cert alongside debug.pk8

Technical Roadmap

  • Native ART Engine Execution: Execute compilation toolchain (ecj, d8, apksigner) natively on Dalvik VM without host JDK dependencies.
  • Java 16 & Google D8 Support: Modernized compilation pipeline with ECJ 3.27.0 and Google D8 dexer replacing legacy dx.
  • Jar & Native Binary Bundling: Automated linking for 3rd-party .jar files in libs/ and .so binaries in lib/.
  • Automatic Multidex Support: DEX splitting and secondary dex injection for large codebases exceeding 64k method limits.
  • Custom Release Keystore Profiles: CLI options (--keystore, --alias, --ks-pass, --key-pass) for production signing.
  • Incremental Compilation Engine: Hashing system to cache resource compilation and Java bytecode, rebuilding only modified sources.
  • Zipalign Optimization Engine: Native 4-byte boundary alignment for uncompressed zip entries prior to signature verification.
  • Kotlin Compiler Support: Integration of kotlinc targeting Dalvik/ART bytecode for .kt source files.
  • AAR & Remote Dependency Resolution: Parsing .aar archives and automated transitive Maven package resolution.
  • Automated ADB Deployment: Device deployment via --install and --launch options using local ADB service.

Maintainer

Created and maintained by Farhan Ali (i.farhanali.dev@gmail.com).