javac-android
Ported JDK compiler for Android runtime.
A port of the standard JDK Java compiler (javac) adapted to run natively within the Android runtime environment. Enables on-device Java compilation for mobile IDEs and developer tools.
Key Features
- • Full javac compiler running on Android
- • Compatible with Android's Dalvik/ART runtime
- • Used by Cosmic IDE and other mobile IDEs
JVM Toolchain Architecture
Compiling Java natively on Android poses non-trivial architectural challenges. The stock OpenJDK compiler relies on desktop-standard filesystem assumptions, sun.misc.Unsafe hooks, and internal module architectures that conflict with Android's Bionic C library and Dalvik/ART execution engine.
javac-android adapts the upstream OpenJDK compiler tree into a distributable Android archive. It enables mobile applications, educational compilers, and development environments like Cosmic IDE to compile Java source files directly on-device without root access or a network connection.
Implementation Highlights
Java 26 & Modern Language Support
Maintains compatibility with contemporary Java syntax, module specifications, and standard ct.sym symbol databases for target release cross-compilation.
Android Runtime Optimization
Patched filesystem wrappers bypass JVM-specific memory-mapped IO operations that trigger restrictions under Android's scoped storage and SELinux policies.
JitPack Distribution
Published as a reusable dependency (com.github.PranavPurwar:javac-android:27.23), allowing any Android application to embed a full Java compiler in seconds.
Memory-Constrained Performance
Engineered to operate inside the strict heap ceilings of Android processes without exhausting process memory or triggering low-memory killer (LMK) aborts.
Integration Example
// Gradle dependency configuration
repositories {
maven { url 'https://jitpack.io' }
}
dependencies {
implementation 'com.github.PranavPurwar:javac-android:27.23'
}