Unverified Commit 9c2f0302 authored by Morgan Jones's avatar Morgan Jones
Browse files

androidenv: ANDROID_SDK_ROOT -> ANDROID_HOME

Change the 'primary' env var to ANDROID_HOME.
Always export ANDROID_SDK_ROOT for compatibility.
parent 051e6e2c
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -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}
+13 −11
Original line number Diff line number Diff line
@@ -27,25 +27,27 @@ deployAndroidPackage {
    ''}

    # Strip double dots from the root path
    export ANDROID_SDK_ROOT="$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
    export ANDROID_HOME="$out/libexec/android-sdk"

    # 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}
  '';

+1 −1
Original line number Diff line number Diff line
@@ -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

+5 −3
Original line number Diff line number Diff line
@@ -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
+2 −3
Original line number Diff line number Diff line
@@ -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
  '';
}
Loading