androidenv: ANDROID_SDK_ROOT -> ANDROID_HOME

Change the 'primary' env var to ANDROID_HOME.
Always export ANDROID_SDK_ROOT for compatibility.
This commit is contained in:
Morgan Jones
2026-04-19 17:32:01 -07:00
parent 051e6e2c9b
commit 9c2f0302bf
8 changed files with 31 additions and 31 deletions
+1 -1
View File
@@ -27,7 +27,7 @@ Alternatively, you can pass composeAndroidPackages to the `withSdk` passthrough:
}
```
These will export `ANDROID_SDK_ROOT` and `ANDROID_NDK_ROOT` to the SDK and NDK directories
These will export `ANDROID_HOME` and `ANDROID_NDK_ROOT` to the SDK and NDK directories
in the specified Android build environment.
## Deploying an Android SDK installation with plugins {#deploying-an-android-sdk-installation-with-plugins}
@@ -27,25 +27,27 @@ deployAndroidPackage {
''}
# Strip double dots from the root path
export ANDROID_SDK_ROOT="$out/libexec/android-sdk"
export ANDROID_HOME="$out/libexec/android-sdk"
# Wrap all scripts that require JAVA_HOME
find $ANDROID_SDK_ROOT/${package.path}/bin -maxdepth 1 -type f -executable | while read program; do
if grep -q "JAVA_HOME" $program; then
wrapProgram $program --prefix PATH : ${pkgs.jdk17}/bin \
--prefix ANDROID_SDK_ROOT : $ANDROID_SDK_ROOT
# Wrap all scripts that require JAVA_HOME.
# Use ANDROID_SDK_ROOT as legacy compatibility but the "correct" way is ANDROID_HOME nowadays (2026+).
find "$ANDROID_HOME/${package.path}/bin" -maxdepth 1 -type f -executable | while read program; do
if grep -q "JAVA_HOME" "$program"; then
wrapProgram "$program" --prefix PATH : ${pkgs.jdk17}/bin \
--prefix ANDROID_HOME : "$ANDROID_HOME" \
--prefix ANDROID_SDK_ROOT : "$ANDROID_HOME"
fi
done
# Wrap sdkmanager script
wrapProgram $ANDROID_SDK_ROOT/${package.path}/bin/sdkmanager \
wrapProgram "$ANDROID_HOME/${package.path}/bin/sdkmanager" \
--prefix PATH : ${lib.makeBinPath [ pkgs.jdk17 ]} \
--add-flags "--sdk_root=$ANDROID_SDK_ROOT"
--add-flags "--sdk_root=$ANDROID_HOME"
# Patch all script shebangs
patchShebangs $ANDROID_SDK_ROOT/${package.path}/bin
patchShebangs "$ANDROID_HOME/${package.path}/bin"
cd $ANDROID_SDK_ROOT
cd "$ANDROID_HOME"
${postInstall}
'';
@@ -798,7 +798,7 @@ lib.recurseIntoAttrs rec {
done
''}
find $ANDROID_SDK_ROOT/${cmdline-tools-package.path}/bin -type f -executable | while read i; do
find "$ANDROID_HOME/${cmdline-tools-package.path}/bin" -type f -executable | while read i; do
ln -s $i $out/bin
done
@@ -87,8 +87,10 @@ stdenv.mkDerivation {
''
}
# We need to specify the location of the Android SDK root folder
export ANDROID_SDK_ROOT=${sdk}/libexec/android-sdk
# We need to specify the location of the Android SDK root folder.
# Still export ANDROID_SDK_ROOT for legacy compatibility.
export ANDROID_HOME=${sdk}/libexec/android-sdk
export ANDROID_SDK_ROOT="$ANDROID_HOME"
${lib.optionalString (androidAvdFlags != null) ''
# If NIX_ANDROID_AVD_FLAGS is empty
@@ -146,7 +148,7 @@ stdenv.mkDerivation {
# Launch the emulator
echo "\nLaunch the emulator"
$ANDROID_SDK_ROOT/emulator/emulator -avd ${deviceName} -no-boot-anim -port $port $NIX_ANDROID_EMULATOR_FLAGS &
"$ANDROID_HOME/emulator/emulator" -avd ${deviceName} -no-boot-anim -port $port $NIX_ANDROID_EMULATOR_FLAGS &
# Wait until the device has completely booted
echo "Waiting until the emulator has booted the ${deviceName} and the package manager is ready..." >&2
@@ -47,14 +47,13 @@ pkgs.mkShell {
LC_ALL = "C.UTF-8";
JAVA_HOME = jdk.home;
# Note: ANDROID_HOME is deprecated. Use ANDROID_SDK_ROOT.
ANDROID_SDK_ROOT = "${androidSdk}/libexec/android-sdk";
ANDROID_HOME = "${androidSdk}/libexec/android-sdk";
shellHook = ''
# Write out local.properties for Android Studio.
cat <<EOF > local.properties
# This file was automatically generated by nix-shell.
sdk.dir=$ANDROID_SDK_ROOT
sdk.dir=$ANDROID_HOME
EOF
'';
}
@@ -97,15 +97,14 @@ pkgs.mkShell rec {
LC_ALL = "C.UTF-8";
JAVA_HOME = jdk.home;
# Note: ANDROID_HOME is deprecated. Use ANDROID_SDK_ROOT.
ANDROID_SDK_ROOT = "${androidSdk}/libexec/android-sdk";
ANDROID_NDK_ROOT = "${ANDROID_SDK_ROOT}/ndk-bundle";
ANDROID_HOME = "${androidSdk}/libexec/android-sdk";
ANDROID_NDK_ROOT = "${ANDROID_HOME}/ndk-bundle";
shellHook = ''
# Write out local.properties for Android Studio.
cat <<EOF > local.properties
# This file was automatically generated by nix-shell.
sdk.dir=$ANDROID_SDK_ROOT
sdk.dir=$ANDROID_HOME
ndk.dir=$ANDROID_NDK_ROOT
EOF
'';
@@ -95,14 +95,13 @@ pkgs.mkShell {
LC_ALL = "C.UTF-8";
JAVA_HOME = jdk.home;
# Note: ANDROID_HOME is deprecated. Use ANDROID_SDK_ROOT.
ANDROID_SDK_ROOT = "${androidSdk}/libexec/android-sdk";
ANDROID_HOME = "${androidSdk}/libexec/android-sdk";
shellHook = ''
# Write out local.properties for Android Studio.
cat <<EOF > local.properties
# This file was automatically generated by nix-shell.
sdk.dir=$ANDROID_SDK_ROOT
sdk.dir=$ANDROID_HOME
EOF
'';
@@ -131,22 +131,21 @@ pkgs.mkShell rec {
LC_ALL = "C.UTF-8";
JAVA_HOME = jdk.home;
# Note: ANDROID_HOME is deprecated. Use ANDROID_SDK_ROOT.
ANDROID_SDK_ROOT = "${androidSdk}/libexec/android-sdk";
ANDROID_NDK_ROOT = "${ANDROID_SDK_ROOT}/ndk-bundle";
ANDROID_HOME = "${androidSdk}/libexec/android-sdk";
ANDROID_NDK_ROOT = "${ANDROID_HOME}/ndk-bundle";
shellHook = ''
# Ensures that we don't have to use a FHS env by using the nix store's aapt2.
export GRADLE_OPTS="-Dorg.gradle.project.android.aapt2FromMavenOverride=$(echo "$ANDROID_SDK_ROOT/build-tools/"*"/aapt2")"
export GRADLE_OPTS="-Dorg.gradle.project.android.aapt2FromMavenOverride=$(echo "$ANDROID_HOME/build-tools/"*"/aapt2")"
# Add cmake to the path.
cmake_root="$(echo "$ANDROID_SDK_ROOT/cmake/"*/)"
cmake_root="$(echo "$ANDROID_HOME/cmake/"*/)"
export PATH="$cmake_root/bin:$PATH"
# Write out local.properties for Android Studio.
cat <<EOF > local.properties
# This file was automatically generated by nix-shell.
sdk.dir=$ANDROID_SDK_ROOT
sdk.dir=$ANDROID_HOME
ndk.dir=$ANDROID_NDK_ROOT
cmake.dir=$cmake_root
EOF