Compiles, packages, and signs Android APKs directly on Android devices via Termux. No host machine, Android Studio, or desktop SDK installation required.
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
- Python >= 3.7
- Termux with
aapt2in$PATH - Runtime toolchain in
~/.kosei/toolchain/(installed viakosei setup)
Create a virtual environment and install in editable mode using uv:
uv venv
uv pip install -e .
kosei setupCreate a project with default package (com.example.hello):
kosei new HelloCreate a project with custom package and directory:
kosei new Hello -p com.mycompany.hello -d ./projectsBuild project in current directory:
kosei buildBuild project in specified directory:
kosei build ./projects/HelloClean build artifacts:
kosei clean ./projects/HelloDownload or repair runtime toolchain:
kosei setupForce re-download complete toolchain:
kosei setup -fAlternative Python module execution:
python -m kosei setup
python -m kosei new Hello
python -m kosei buildBuild Outputs:
build/[AppName].apk— Unsigned intermediate package inside the project build directory[AppName].apk— v1/v2/v3 signed APK ready for installation
All runtime binaries execute natively on Android's dalvikvm engine and are managed via kosei setup from kosei-toolchain.
| 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 |
- 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.
Created and maintained by Farhan Ali (i.farhanali.dev@gmail.com).