How to Set Up a Java/Android Dev Environment
Overview
The Coral NPU stack uses two language ecosystems:
-
Kotlin/JVM (SKaiNET): model definition, tensor DSL, HLO compilation
-
Python (iree-tools): MLIR transpilation, simulator integration
This guide sets up both, using jenv for Java version management and uv for Python.
Install jenv (Java Version Manager)
jenv lets you switch between JDK versions per-project without modifying system settings.
# Clone jenv
git clone https://github.com/jenv/jenv.git ~/.jenv
# Add to shell (zsh)
echo 'export PATH="$HOME/.jenv/bin:$PATH"' >> ~/.zshrc
echo 'eval "$(jenv init -)"' >> ~/.zshrc
source ~/.zshrc
# Enable Gradle plugin (sets JAVA_HOME automatically)
jenv enable-plugin gradle
jenv enable-plugin export
Install JDK 21
SKaiNET requires JDK 21+ for the JDK Vector API (SIMD operations).
Ubuntu/Debian
sudo apt update
sudo apt install openjdk-21-jdk
# Register with jenv
jenv add /usr/lib/jvm/java-21-openjdk-amd64
macOS (Homebrew)
brew install openjdk@21
jenv add /opt/homebrew/opt/openjdk@21/libexec/openjdk.jdk/Contents/Home
Install uv (Python Environment Manager)
uv manages Python versions and virtual environments. No system Python installation needed.
curl -LsSf https://astral.sh/uv/install.sh | sh
# Verify
uv --version
Install Bazel
Bazel builds the Coral NPU cross-compilation toolchain and simulator.
# Via Bazelisk (recommended — auto-downloads correct Bazel version)
npm install -g @aspect-bazel/bazelisk
# Verify
bazel --version
# bazel 7.4.1
Build SKaiNET
cd coral/SKaiNET
# Ensure JDK 21 is active
jenv local 21
# Build all modules
./gradlew build
# Build specific modules
./gradlew :skainet-lang:skainet-lang-core:build
./gradlew :skainet-compile:skainet-compile-hlo:build
./gradlew :skainet-apps:skainet-grayscale-cli:build
# Run tests
./gradlew test
Key Gradle Tasks for Android/Java Developers
| Task | Purpose |
|---|---|
|
Build all modules |
|
Run all tests |
|
Run the grayscale CLI |
|
Publish to local Maven repo (for Android project integration) |
|
Export StableHLO MLIR |
|
Generate test coverage report |
Build the MPACT Simulator
cd coral/coralnpu
bazel build //sim:coralnpu_v2_sim
The simulator requires the host Clang toolchain constraint (//toolchain/host_clang:clang_compiler). If Clang is not installed, sudo apt install clang (Ubuntu/Debian).
|
Project Structure for Android Integration
To use SKaiNET in an Android project, add the Maven dependency after publishing locally:
// build.gradle.kts (Android module)
dependencies {
implementation("sk.ainet:skainet-lang-core:0.1.0")
implementation("sk.ainet:skainet-compile-hlo:0.1.0")
implementation("sk.ainet:skainet-io-image:0.1.0")
}
Android-Specific Considerations
- JDK Vector API
-
Not available on Android. Use
skainet-backend-cpuwith the non-SIMD fallback, or target thenativeKotlin Multiplatform target for computation-heavy workloads. - Model Deployment
-
For on-device inference, export to StableHLO and compile offline. Ship the compiled artifact (ELF for NPU, or native library for CPU) with the APK.
- Memory
-
Android devices have more RAM than the Coral NPU, but you should still profile memory usage when working with large models.
Verify the Full Stack
Run the end-to-end pipeline to confirm everything works:
# 1. Build SKaiNET
cd coral/SKaiNET && jenv local 21 && ./gradlew build
# 2. Run grayscale CLI
./gradlew :skainet-apps:skainet-grayscale-cli:run \
--args="--input test.jpg --verbose"
# 3. Run iree-tools pipeline
cd ../iree-tools && uv run python main.py run-all rgb2grayscale.mlir
# 4. Build and run on simulator
cd ../coralnpu && bazel run //sim:coralnpu_v2_sim -- \
$(pwd)/bazel-bin/examples/generated/rgb2grayscale/coralnpu_v2_rgb2grayscale.elf