diff --git a/doc/languages-frameworks/android.section.md b/doc/languages-frameworks/android.section.md index 63d940279662..316264ba0c1f 100644 --- a/doc/languages-frameworks/android.section.md +++ b/doc/languages-frameworks/android.section.md @@ -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} diff --git a/pkgs/development/mobile/androidenv/cmdline-tools.nix b/pkgs/development/mobile/androidenv/cmdline-tools.nix index 3b561c64452b..77c064ac4f59 100644 --- a/pkgs/development/mobile/androidenv/cmdline-tools.nix +++ b/pkgs/development/mobile/androidenv/cmdline-tools.nix @@ -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} ''; diff --git a/pkgs/development/mobile/androidenv/compose-android-packages.nix b/pkgs/development/mobile/androidenv/compose-android-packages.nix index 1b735da0b2b6..7a92939e33fb 100644 --- a/pkgs/development/mobile/androidenv/compose-android-packages.nix +++ b/pkgs/development/mobile/androidenv/compose-android-packages.nix @@ -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 diff --git a/pkgs/development/mobile/androidenv/emulate-app.nix b/pkgs/development/mobile/androidenv/emulate-app.nix index 9b52a3ff0940..53eb5d04691b 100644 --- a/pkgs/development/mobile/androidenv/emulate-app.nix +++ b/pkgs/development/mobile/androidenv/emulate-app.nix @@ -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 diff --git a/pkgs/development/mobile/androidenv/examples/shell-ifd.nix b/pkgs/development/mobile/androidenv/examples/shell-ifd.nix index 254bc6112311..3024fa43f7ad 100644 --- a/pkgs/development/mobile/androidenv/examples/shell-ifd.nix +++ b/pkgs/development/mobile/androidenv/examples/shell-ifd.nix @@ -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 < local.properties # This file was automatically generated by nix-shell. - sdk.dir=$ANDROID_SDK_ROOT + sdk.dir=$ANDROID_HOME EOF ''; } diff --git a/pkgs/development/mobile/androidenv/examples/shell-with-emulator.nix b/pkgs/development/mobile/androidenv/examples/shell-with-emulator.nix index 43d815004c50..2cf08f55027f 100644 --- a/pkgs/development/mobile/androidenv/examples/shell-with-emulator.nix +++ b/pkgs/development/mobile/androidenv/examples/shell-with-emulator.nix @@ -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 < 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 ''; diff --git a/pkgs/development/mobile/androidenv/examples/shell-without-emulator.nix b/pkgs/development/mobile/androidenv/examples/shell-without-emulator.nix index 353379aca50f..61a2ab103fa2 100644 --- a/pkgs/development/mobile/androidenv/examples/shell-without-emulator.nix +++ b/pkgs/development/mobile/androidenv/examples/shell-without-emulator.nix @@ -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 < local.properties # This file was automatically generated by nix-shell. - sdk.dir=$ANDROID_SDK_ROOT + sdk.dir=$ANDROID_HOME EOF ''; diff --git a/pkgs/development/mobile/androidenv/examples/shell.nix b/pkgs/development/mobile/androidenv/examples/shell.nix index 276867ae2bcd..036a7df3655e 100644 --- a/pkgs/development/mobile/androidenv/examples/shell.nix +++ b/pkgs/development/mobile/androidenv/examples/shell.nix @@ -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 < 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