about summary refs log tree commit diff
path: root/pkgs/development/mobile
diff options
context:
space:
mode:
authorHadi <hadilq.dev@gmail.com>2024-01-22 17:41:51 -0500
committerHadi <hadilq.dev@gmail.com>2024-01-22 19:04:40 -0500
commit3f00b40fff0e6de822196dd926d8efca430b490b (patch)
treed6016940157859e2320c2ccc725fbf3e52062877 /pkgs/development/mobile
parente7120ab3810ca54256f40324b3893b886fd70570 (diff)
androidenv: don't include emulator when includeEmulator is false
Diffstat (limited to 'pkgs/development/mobile')
-rw-r--r--pkgs/development/mobile/androidenv/compose-android-packages.nix14
-rw-r--r--pkgs/development/mobile/androidenv/examples/shell-with-emulator.nix33
-rw-r--r--pkgs/development/mobile/androidenv/examples/shell-without-emulator.nix152
-rw-r--r--pkgs/development/mobile/androidenv/test-suite.nix10
-rw-r--r--pkgs/development/mobile/androidenv/tools.nix2
5 files changed, 200 insertions, 11 deletions
diff --git a/pkgs/development/mobile/androidenv/compose-android-packages.nix b/pkgs/development/mobile/androidenv/compose-android-packages.nix
index 8d3f7f6e20dfe..a0ab34cef33c3 100644
--- a/pkgs/development/mobile/androidenv/compose-android-packages.nix
+++ b/pkgs/development/mobile/androidenv/compose-android-packages.nix
@@ -151,7 +151,7 @@ rec {
     postInstall = ''
       ${linkPlugin { name = "platform-tools"; plugin = platform-tools; }}
       ${linkPlugin { name = "patcher"; plugin = patcher; }}
-      ${linkPlugin { name = "emulator"; plugin = emulator; }}
+      ${linkPlugin { name = "emulator"; plugin = emulator; check = includeEmulator; }}
     '';
   };
 
@@ -171,14 +171,14 @@ rec {
     }
   ) buildToolsVersions;
 
-  emulator = callPackage ./emulator.nix {
+  emulator = lib.optionals includeEmulator (callPackage ./emulator.nix {
     inherit deployAndroidPackage os;
     package = check-version packages "emulator" emulatorVersion;
 
     postInstall = ''
       ${linkSystemImages { images = system-images; check = includeSystemImages; }}
     '';
-  };
+  });
 
   platforms = map (version:
     deployAndroidPackage {
@@ -373,9 +373,11 @@ rec {
           ln -s $i $out/bin
       done
 
-      for i in ${emulator}/bin/*; do
-          ln -s $i $out/bin
-      done
+      ${lib.optionalString includeEmulator ''
+        for i in ${emulator}/bin/*; do
+            ln -s $i $out/bin
+        done
+      ''}
 
       find $ANDROID_SDK_ROOT/${cmdline-tools-package.path}/bin -type f -executable | while read i; do
           ln -s $i $out/bin
diff --git a/pkgs/development/mobile/androidenv/examples/shell-with-emulator.nix b/pkgs/development/mobile/androidenv/examples/shell-with-emulator.nix
index 3c08887eb5be1..1315b1ff98a2b 100644
--- a/pkgs/development/mobile/androidenv/examples/shell-with-emulator.nix
+++ b/pkgs/development/mobile/androidenv/examples/shell-with-emulator.nix
@@ -132,6 +132,39 @@ pkgs.mkShell rec {
       touch "$out"
     '';
 
+    shell-with-emulator-sdkmanager-excluded-packages-test = pkgs.runCommand "shell-with-emulator-sdkmanager-excluded-packages-test"
+      {
+        nativeBuildInputs = [ androidSdk jdk ];
+      } ''
+      output="$(sdkmanager --list)"
+      installed_packages_section=$(echo "''${output%%Available Packages*}" | awk 'NR>4 {print $1}')
+
+      excluded_packages=(
+        "platforms;android-23" "platforms;android-24" "platforms;android-25" "platforms;android-26" \
+        "platforms;android-27" "platforms;android-28" "platforms;android-29" "platforms;android-30" \
+        "platforms;android-31" "platforms;android-32" "platforms;android-33" \
+        "sources;android-23" "sources;android-24" "sources;android-25" "sources;android-26" \
+        "sources;android-27" "sources;android-28" "sources;android-29" "sources;android-30" \
+        "sources;android-31" "sources;android-32" "sources;android-33" "sources;android-34" \
+        "system-images;android-28" \
+        "system-images;android-29" \
+        "system-images;android-30" \
+        "system-images;android-31" \
+        "system-images;android-32" \
+        "system-images;android-33" \
+        "ndk"
+      )
+
+      for package in "''${excluded_packages[@]}"; do
+        if [[ $installed_packages_section =~ "$package" ]]; then
+          echo "$package package was installed, while it was excluded!"
+          exit 1
+        fi
+      done
+
+      touch "$out"
+    '';
+
     shell-with-emulator-avdmanager-create-avd-test = pkgs.runCommand "shell-with-emulator-avdmanager-create-avd-test" {
       nativeBuildInputs = [ androidSdk androidEmulator jdk ];
     } ''
diff --git a/pkgs/development/mobile/androidenv/examples/shell-without-emulator.nix b/pkgs/development/mobile/androidenv/examples/shell-without-emulator.nix
new file mode 100644
index 0000000000000..ec7020a0c9a90
--- /dev/null
+++ b/pkgs/development/mobile/androidenv/examples/shell-without-emulator.nix
@@ -0,0 +1,152 @@
+{
+  # To test your changes in androidEnv run `nix-shell android-sdk-with-emulator-shell.nix`
+
+  # If you copy this example out of nixpkgs, use these lines instead of the next.
+  # This example pins nixpkgs: https://nix.dev/tutorials/towards-reproducibility-pinning-nixpkgs.html
+  /*nixpkgsSource ? (builtins.fetchTarball {
+    name = "nixpkgs-20.09";
+    url = "https://github.com/NixOS/nixpkgs/archive/20.09.tar.gz";
+    sha256 = "1wg61h4gndm3vcprdcg7rc4s1v3jkm5xd7lw8r2f67w502y94gcy";
+    }),
+    pkgs ? import nixpkgsSource {
+    config.allowUnfree = true;
+    },
+  */
+
+  # If you want to use the in-tree version of nixpkgs:
+  pkgs ? import ../../../../.. {
+    config.allowUnfree = true;
+  }
+, config ? pkgs.config
+}:
+
+# Copy this file to your Android project.
+let
+  # Declaration of versions for everything. This is useful since these
+  # versions may be used in multiple places in this Nix expression.
+  android = {
+    versions = {
+      cmdLineToolsVersion = "11.0";
+      platformTools = "34.0.5";
+      buildTools = "34.0.0";
+    };
+    platforms = [ "34" ];
+  };
+
+  # If you copy this example out of nixpkgs, something like this will work:
+  /*androidEnvNixpkgs = fetchTarball {
+    name = "androidenv";
+    url = "https://github.com/NixOS/nixpkgs/archive/<fill me in from Git>.tar.gz";
+    sha256 = "<fill me in with nix-prefetch-url --unpack>";
+    };
+
+    androidEnv = pkgs.callPackage "${androidEnvNixpkgs}/pkgs/development/mobile/androidenv" {
+    inherit config pkgs;
+    licenseAccepted = true;
+    };*/
+
+  # Otherwise, just use the in-tree androidenv:
+  androidEnv = pkgs.callPackage ./.. {
+    inherit config pkgs;
+    # You probably need to uncomment below line to express consent.
+    # licenseAccepted = true;
+  };
+
+  sdkArgs = {
+    cmdLineToolsVersion = android.versions.cmdLineToolsVersion;
+    platformToolsVersion = android.versions.platformTools;
+    buildToolsVersions = [ android.versions.buildTools ];
+    platformVersions = android.platforms;
+    includeNDK = false;
+    includeSystemImages = false;
+    includeEmulator = false;
+
+    # Accepting more licenses declaratively:
+    extraLicenses = [
+      # Already accepted for you with the global accept_license = true or
+      # licenseAccepted = true on androidenv.
+      # "android-sdk-license"
+
+      # These aren't, but are useful for more uncommon setups.
+      "android-sdk-preview-license"
+      "android-googletv-license"
+      "android-sdk-arm-dbt-license"
+      "google-gdk-license"
+      "intel-android-extra-license"
+      "intel-android-sysimage-license"
+      "mips-android-sysimage-license"
+    ];
+  };
+
+  androidComposition = androidEnv.composeAndroidPackages sdkArgs;
+  androidSdk = androidComposition.androidsdk;
+  platformTools = androidComposition.platform-tools;
+  jdk = pkgs.jdk;
+in
+pkgs.mkShell rec {
+  name = "androidenv-example-without-emulator-demo";
+  packages = [ androidSdk platformTools jdk pkgs.android-studio ];
+
+  LANG = "C.UTF-8";
+  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";
+
+  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
+    EOF
+  '';
+
+  passthru.tests = {
+
+    shell-without-emulator-sdkmanager-packages-test = pkgs.runCommand "shell-without-emulator-sdkmanager-packages-test"
+      {
+        nativeBuildInputs = [ androidSdk jdk ];
+      } ''
+      output="$(sdkmanager --list)"
+      installed_packages_section=$(echo "''${output%%Available Packages*}" | awk 'NR>4 {print $1}')
+      echo "installed_packages_section: ''${installed_packages_section}"
+
+      packages=(
+        "build-tools;34.0.0" "cmdline-tools;11.0" \
+        "patcher;v4" "platform-tools" "platforms;android-34"
+      )
+
+      for package in "''${packages[@]}"; do
+        if [[ ! $installed_packages_section =~ "$package" ]]; then
+          echo "$package package was not installed."
+          exit 1
+        fi
+      done
+
+      touch "$out"
+    '';
+
+    shell-without-emulator-sdkmanager-excluded-packages-test = pkgs.runCommand "shell-without-emulator-sdkmanager-excluded-packages-test"
+      {
+        nativeBuildInputs = [ androidSdk jdk ];
+      } ''
+      output="$(sdkmanager --list)"
+      installed_packages_section=$(echo "''${output%%Available Packages*}" | awk 'NR>4 {print $1}')
+
+      excluded_packages=(
+        "emulator" "ndk"
+      )
+
+      for package in "''${excluded_packages[@]}"; do
+        if [[ $installed_packages_section =~ "$package" ]]; then
+          echo "$package package was installed, while it was excluded!"
+          exit 1
+        fi
+      done
+
+      touch "$out"
+    '';
+  };
+}
+
diff --git a/pkgs/development/mobile/androidenv/test-suite.nix b/pkgs/development/mobile/androidenv/test-suite.nix
index b5aeca4324617..c3a8cc64f0f4b 100644
--- a/pkgs/development/mobile/androidenv/test-suite.nix
+++ b/pkgs/development/mobile/androidenv/test-suite.nix
@@ -1,9 +1,11 @@
-{callPackage, lib, stdenv}:
+{ callPackage, lib, stdenv }:
 let
-  examples-shell = callPackage ./examples/shell.nix {};
-  examples-shell-with-emulator = callPackage ./examples/shell-with-emulator.nix {};
+  examples-shell = callPackage ./examples/shell.nix { };
+  examples-shell-with-emulator = callPackage ./examples/shell-with-emulator.nix { };
+  examples-shell-without-emulator = callPackage ./examples/shell-without-emulator.nix { };
   all-tests = examples-shell.passthru.tests //
-    examples-shell-with-emulator.passthru.tests;
+    (examples-shell-with-emulator.passthru.tests //
+      examples-shell-without-emulator.passthru.tests);
 in
 stdenv.mkDerivation {
   name = "androidenv-test-suite";
diff --git a/pkgs/development/mobile/androidenv/tools.nix b/pkgs/development/mobile/androidenv/tools.nix
index 0177d8e6f7b77..91ddbe4f9edc4 100644
--- a/pkgs/development/mobile/androidenv/tools.nix
+++ b/pkgs/development/mobile/androidenv/tools.nix
@@ -1,7 +1,7 @@
 {deployAndroidPackage, lib, package, autoPatchelfHook, makeWrapper, os, pkgs, pkgsi686Linux, postInstall}:
 
 deployAndroidPackage {
-  name = "androidsdk";
+  name = "androidsdk-tools";
   inherit os package;
   nativeBuildInputs = [ makeWrapper ]
     ++ lib.optionals (os == "linux") [ autoPatchelfHook ];