The x86_64 emulator was running the arm64 .so through the native bridge, which returns JNI jbooleans with junk in the register's upper bits. Since jni-sys 0.4 reads jboolean as a Rust bool, every ExceptionCheck reported a pending exception, so rustls-platform-verifier could neither initialize nor verify a certificate on the emulator. Still one Rust cross-compile per build: -PrustAbi wins, else the ABI Android Studio injects for the device it deploys to, else arm64-v8a. The .so is now synced into build/rustJniLibs rather than src/main/jniLibs, so clean removes it and a previously built ABI can't ride along in the APK. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
11 KiB
Build & CI Setup
Local Development
Without Nix
Requires:
- JDK 17 (or Android Studio's bundled JBR at
/opt/android-studio/jbr) - Android SDK 35, NDK 28.0.13004108
- Rust stable with the
aarch64-linux-androidtarget, plusx86_64-linux-androidto run on an x86_64 emulator
Set JAVA_HOME and run:
cd android && ./gradlew assembleDebug
The Rust library is built for one ABI per build — cross-compiling it is the
slow part. Android Studio's Run builds whatever the target device uses
(x86_64 for an emulator on an x86 host, arm64-v8a for a phone); a
command-line build defaults to arm64-v8a, and -PrustAbi=x86_64 overrides
it. Don't install an arm64 build on an x86_64 emulator: its native bridge
breaks JNI boolean returns, and TLS stops working (see the
build-synchronicity-lib-android recipe).
Or use the justfile recipes:
just android-build # build debug APK
just build-synchronicity-lib-android # build Rust library only (arm64-v8a)
just build-synchronicity-lib-android x86_64 # ...for an x86_64 emulator
just fmt-kotlin # format Kotlin code
just fmt-kotlin-check # check Kotlin formatting
With Nix
The repo includes a flake.nix that provides a dev shell with all dependencies pinned (Android SDK, NDK, Rust + cross target, JDK 17).
nix develop
cd android && ./gradlew assembleDebug
CI: Automated APK Builds with Gitea Actions
The workflow in .gitea/workflows/build-apk.yml builds a debug APK on every push to master and publishes it as a Gitea release. This is designed for use with Obtainium for easy installation on a physical device.
Prerequisites
- A Gitea instance with Actions enabled (requires
ENABLED=trueunder[actions]in Gitea'sapp.ini) - A NixOS machine to host the runner
1. Set up the Gitea Actions runner (NixOS)
Add to your NixOS configuration:
services.gitea-actions-runner = {
instances.default = {
enable = true;
url = "https://your-gitea-url";
tokenFile = "/var/lib/gitea-runner/token";
name = "nix-runner";
labels = [
"nix:host" # runs jobs directly on the host, not in Docker
];
settings = {
runner.timeout = "3h";
};
};
};
2. Generate a runner registration token
In Gitea: Site Administration > Actions > Runners > Create new Runner. Copy the token and write it to /var/lib/gitea-runner/token on the runner machine.
3. Create a GITEA_TOKEN secret
Generate a personal access token in Gitea with write:repository permission. Then in your repo: Settings > Actions > Secrets — add a secret named GITEA_TOKEN with the token value. This is used by the workflow to create releases and upload the APK.
4. Enable Actions on the repository
In your repo: Settings > Repository — check "Enable Repository Actions".
5. Deploy and test
Run nixos-rebuild switch on the runner machine, then push to master. The workflow will:
- Check out the repo
- Enter the Nix dev shell (Android SDK, Rust, etc.)
- Build the debug APK via Gradle
- Create a pre-release tagged
build-<short-sha>with the APK attached - Prune old
build-*releases (and their tags/attachments), keeping the 10 most recent, to keep the Gitea server's disk usage bounded
6. Configure Obtainium
Install Obtainium from F-Droid, add your Gitea repo URL as a source (select "Gitea" as the source type), and it will track releases and notify you when new builds are available.
Troubleshooting
NDK version not found in Nix
The androidenv in nixpkgs may not have every NDK point release. If nix develop fails because NDK 28.0.13004108 isn't available, check what versions exist:
nix repl nixpkgs --expr 'let pkgs = import <nixpkgs> { config.android_sdk.accept_license = true; }; in builtins.attrNames (pkgs.androidenv.composeAndroidPackages { includeNDK = true; }).ndk-bundles'
Then update the NDK version in both flake.nix and android/app/build.gradle.kts to match an available version.
Gradle can't find Android SDK in Nix shell
Make sure ANDROID_HOME is set. Inside nix develop this is automatic. If running outside Nix, set it manually:
export ANDROID_HOME="$HOME/Android/Sdk"
Disk usage
Both build caches this project uses — rust/target/ and /nix/store — grow
without bound by design. Neither ever reclaims space on its own, so the failure
mode is a full disk mid-build, followed by a cargo clean and a from-scratch
rebuild. The settings below are meant to replace that cycle: shrink each
artifact, then cap the total automatically.
Measured baseline (August 2026, one workstation): 170 GB for the checkout, 144 GB
of it in rust/target/.
Why it grows
Cargo writes one hash-suffixed artifact per distinct build configuration —
rustc version, feature set, profile, git-dependency revision — and never deletes
the superseded ones. gpui and gpui_platform are git dependencies, so every
upstream revision the lockfile moves to mints a fresh set. The baseline above
held 849 syn_gui objects and 516 incremental/ session directories.
Individual artifacts are also far larger than they need to be, because debug
info dominates them. A debug syn-gui measured 1.11 GB, of which 858 MB (77%)
was DWARF against 105 MB of .text. Dependency rlibs measured 34–70% debug info
(libmupdf_sys alone: 288 MB, 70% debug).
What's configured
rust/Cargo.toml's dev profile addresses artifact size:
debug = "line-tables-only"on workspace crates. The previousdebug = 1is Cargo's "limited" level despite what it sounds like — it still emits.debug_infoand.debug_locfor every type and local.line-tables-onlykeepsfile:linein backtraces and panics, which is what we actually read.debug = falseon dependencies ([profile.dev.package."*"], which covers dependencies only, never workspace members). We don't step into them, and atopt-level = 3inlining makes their line numbers untrustworthy anyway. Set it to"line-tables-only"if you ever need frames inside a dependency.split-debuginfo = "unpacked", so each of the many hashed binaries indeps/references shared per-crate debug info instead of carrying its own copy of the whole dependency tree's.strip = "debuginfo"on release, which is what Nix packages and what ships to Android — otherwise that DWARF is paid for again in/nix/storeand in crane'scargoArtifactsclosure.
just gc-target [size] [days] addresses accumulation, and
just install-gc-timer runs it weekly via a systemd user timer. It needs two
mechanisms because they cover disjoint parts of the tree: cargo sweep --maxsize evicts oldest-first from deps/, build/, and examples/, but is
blind to incremental/, which the recipe prunes by age. Use just target-usage
to see the breakdown before assuming a cargo clean is warranted.
Note that cargo sweep --installed and --time are both weak here: nearly
everything was built by a currently-installed toolchain, and the churn is recent
enough that an age filter misses it. --maxsize is the mode that behaves like a
cap.
What cargo clean does not cover
cargo clean is exhaustive for the target directory of the workspace it runs
in, and nothing else. Four categories survive it, together measured at ~7.5 GB:
- Other target directories in the same checkout.
cargo cleaninrust/cleansrust/targetonly.rust/archive/gui-slintisexcluded from the workspace and would get its own if it were ever built;rust/gui-apphad one for the same reason before it became a workspace member, and it sat there holding 24 GB for two months.find . -type d -name target -prunefinds them all;cargo sweep --recursivecleans them. ~/.cargo, measured at 2.6 GB of registry (2.0 GB unpackedsrc, 462 MB of.cratetarballs incache, 97 MB index) plus 919 MB of git dependency checkouts — inflated here becausegpuiis a git dependency. Stable cargo has no GC for any of it (-Z gcis nightly-only).registry/srcis just unpacked copies ofregistry/cache, so deletingsrcalone re-extracts locally rather than re-downloading.~/.rustup, 3.7 GB of toolchains.rustup component remove rust-docssaves a few hundred MB per toolchain kept.- Nix. Crane's
cargoArtifactsclosure and everynix buildoutput are in/nix/store, and theresultsymlink is a GC root pinning one. See below.
gui-store/ is dev runtime data rather than a build artifact, so nothing
cleans it automatically.
Kotlin
just gradlew clean is the analogue and is less complete than cargo clean:
- It removes
android/app/build(1.8 GB) andandroid/build, but notandroid/.gradle, the per-project incremental state. ~/.gradleis shared and untouched: 4.2 GB ofcaches, plus awrapperdirectory holding every Gradle distribution ever used, not just the current one.
Unlike cargo, Gradle can bound its own caches — it is simply off by default.
Create ~/.gradle/init.d/cache-cleanup.gradle.kts:
import org.gradle.api.cache.Cleanup
beforeSettings {
caches {
cleanup.set(Cleanup.ALWAYS)
releasedWrappers.setRemoveUnusedEntriesAfterDays(30)
snapshotWrappers.setRemoveUnusedEntriesAfterDays(7)
downloadedResources.setRemoveUnusedEntriesAfterDays(30)
createdResources.setRemoveUnusedEntriesAfterDays(14)
buildCache.setRemoveUnusedEntriesAfterDays(7)
}
}
Verified against Gradle 9.5.0, this project's wrapper version. Use the explicit
set…() calls: the property-assignment form these docs are usually written with
(releasedWrappers.removeUnusedEntriesAfterDays = 30) fails to compile on
Gradle 9, because CacheResourceConfiguration exposes the setter without a
matching getter, so Kotlin cannot synthesize the property.
Finally, the largest Android consumer is not a build artifact at all: the SDK at
$ANDROID_HOME runs to 21 GB, most of it NDKs at ~2 GB each. Only the version
pinned by ANDROID_NDK_VERSION in the justfile is used, and the Nix path
(just build-android-nix) supplies its own regardless, so any other installed
NDK is reclaimable.
Nix
The store needs the same treatment, on every machine that builds — including
remote builders, where a nix build that overflows the disk fails just as hard.
A calendar GC (nix.gc.automatic with dates = "weekly") does not prevent this
on its own: it runs on a schedule, not under pressure, so a single large build
between runs still fills the disk. min-free/max-free is the setting that
does, because the daemon collects garbage during a build when free space drops
below the threshold. Size them against this workspace's build, not against a
default — one cargo phase here can write tens of GB, so a max-free of a few
GB frees space the same build immediately reconsumes.
Also worth checking per machine:
keep-derivations. Where it'strue,.drvpaths dominate the store — the workstation baseline had 285k of 353k paths as.drv.- Accumulated profile generations (home-manager's in particular), each pinning
its closure.
home-manager expire-generationsandnix-collect-garbage --delete-older-thanbound them. - Stray
resultsymlinks in checkouts. Each is a GC root pinning a full closure;nix build --no-link --print-out-pathsavoids creating one.