Compiles, packages, and signs Android APKs directly on Android via Termux using native ART execution.
- Python 81.3%
- Java 18.7%
| Filename | Latest commit message | Latest commit date |
|---|---|---|
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. |
||
| src | ||
| tools | ||
| .gitignore | ||
| .python-version | ||
| LICENSE | ||
| pyproject.toml | ||
| README.md | ||
| uv.lock | ||
kosei
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
aapt2in$PATH - ART at
/apex/com.android.art/bin/dalvikvmor/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
.jarfiles inlibs/and.sobinaries inlib/. - 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
kotlinctargeting Dalvik/ART bytecode for.ktsource files. - AAR & Remote Dependency Resolution: Parsing
.aararchives and automated transitive Maven package resolution. - Automated ADB Deployment: Device deployment via
--installand--launchoptions using local ADB service.
Maintainer
Created and maintained by Farhan Ali (i.farhanali.dev@gmail.com).