Add Nix flake dev shell for building on NixOS
Provides JDK 21 and an Android SDK (platforms 36/36.1, build-tools 36.0.0) via `nix develop`. Points AGP at the SDK's aapt2 and Gradle at the Nix JDK, since the binaries they would otherwise download do not run on NixOS. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,64 @@
|
||||
{
|
||||
description = "FatihsMG4 — Android Automotive build environment";
|
||||
|
||||
inputs = {
|
||||
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
|
||||
};
|
||||
|
||||
outputs = { self, nixpkgs }:
|
||||
let
|
||||
systems = [ "x86_64-linux" "aarch64-linux" ];
|
||||
forAllSystems = f: nixpkgs.lib.genAttrs systems (system: f (import nixpkgs {
|
||||
inherit system;
|
||||
config = {
|
||||
allowUnfree = true;
|
||||
android_sdk.accept_license = true;
|
||||
};
|
||||
}));
|
||||
|
||||
# Must match app/build.gradle (compileSdk 36.1) and EVHardware/lib (compileSdk 36).
|
||||
buildToolsVersion = "36.0.0";
|
||||
in
|
||||
{
|
||||
devShells = forAllSystems (pkgs:
|
||||
let
|
||||
android = pkgs.androidenv.composeAndroidPackages {
|
||||
platformVersions = [ "36" "36.1" ];
|
||||
buildToolsVersions = [ buildToolsVersion ];
|
||||
includeEmulator = false;
|
||||
includeNDK = false;
|
||||
includeSources = false;
|
||||
includeSystemImages = false;
|
||||
};
|
||||
sdk = "${android.androidsdk}/libexec/android-sdk";
|
||||
# gradle/gradle-daemon-jvm.properties pins the daemon to JDK 21.
|
||||
jdk = pkgs.jdk21;
|
||||
in
|
||||
{
|
||||
default = pkgs.mkShell {
|
||||
packages = [ jdk android.androidsdk ];
|
||||
|
||||
ANDROID_HOME = sdk;
|
||||
ANDROID_SDK_ROOT = sdk;
|
||||
JAVA_HOME = jdk.home;
|
||||
|
||||
# AGP otherwise downloads an aapt2 binary from Maven, which is dynamically linked
|
||||
# against a generic FHS and does not run on NixOS. Use the SDK's patched one.
|
||||
# Gradle is also pointed at the Nix JDK so the daemon toolchain criteria are met
|
||||
# locally instead of downloading a (non-NixOS) JDK through foojay.
|
||||
GRADLE_OPTS = builtins.concatStringsSep " " [
|
||||
"-Dorg.gradle.project.android.aapt2FromMavenOverride=${sdk}/build-tools/${buildToolsVersion}/aapt2"
|
||||
"-Dorg.gradle.java.installations.paths=${jdk.home}"
|
||||
"-Dorg.gradle.java.installations.auto-download=false"
|
||||
];
|
||||
|
||||
shellHook = ''
|
||||
echo "sdk.dir=$ANDROID_HOME" > local.properties
|
||||
echo "FatihsMG4 dev shell — JDK $(java -version 2>&1 | head -1 | cut -d'"' -f2), SDK at $ANDROID_HOME"
|
||||
echo " ./gradlew assembleStableDebug build a debug APK"
|
||||
echo " ./gradlew testStableDebugUnitTest run unit tests"
|
||||
'';
|
||||
};
|
||||
});
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user