Merge pull request #283035 from hadilq/androidenv-composeAndroidPackages-always-includes-emulator

authored by Sandro and committed by GitHub aeddcf46 ff2a77ca

+200 -11
+8 -6
pkgs/development/mobile/androidenv/compose-android-packages.nix
··· 151 151 postInstall = '' 152 152 ${linkPlugin { name = "platform-tools"; plugin = platform-tools; }} 153 153 ${linkPlugin { name = "patcher"; plugin = patcher; }} 154 - ${linkPlugin { name = "emulator"; plugin = emulator; }} 154 + ${linkPlugin { name = "emulator"; plugin = emulator; check = includeEmulator; }} 155 155 ''; 156 156 }; 157 157 ··· 171 171 } 172 172 ) buildToolsVersions; 173 173 174 - emulator = callPackage ./emulator.nix { 174 + emulator = lib.optionals includeEmulator (callPackage ./emulator.nix { 175 175 inherit deployAndroidPackage os; 176 176 package = check-version packages "emulator" emulatorVersion; 177 177 178 178 postInstall = '' 179 179 ${linkSystemImages { images = system-images; check = includeSystemImages; }} 180 180 ''; 181 - }; 181 + }); 182 182 183 183 platforms = map (version: 184 184 deployAndroidPackage { ··· 373 373 ln -s $i $out/bin 374 374 done 375 375 376 - for i in ${emulator}/bin/*; do 377 - ln -s $i $out/bin 378 - done 376 + ${lib.optionalString includeEmulator '' 377 + for i in ${emulator}/bin/*; do 378 + ln -s $i $out/bin 379 + done 380 + ''} 379 381 380 382 find $ANDROID_SDK_ROOT/${cmdline-tools-package.path}/bin -type f -executable | while read i; do 381 383 ln -s $i $out/bin
+33
pkgs/development/mobile/androidenv/examples/shell-with-emulator.nix
··· 132 132 touch "$out" 133 133 ''; 134 134 135 + shell-with-emulator-sdkmanager-excluded-packages-test = pkgs.runCommand "shell-with-emulator-sdkmanager-excluded-packages-test" 136 + { 137 + nativeBuildInputs = [ androidSdk jdk ]; 138 + } '' 139 + output="$(sdkmanager --list)" 140 + installed_packages_section=$(echo "''${output%%Available Packages*}" | awk 'NR>4 {print $1}') 141 + 142 + excluded_packages=( 143 + "platforms;android-23" "platforms;android-24" "platforms;android-25" "platforms;android-26" \ 144 + "platforms;android-27" "platforms;android-28" "platforms;android-29" "platforms;android-30" \ 145 + "platforms;android-31" "platforms;android-32" "platforms;android-33" \ 146 + "sources;android-23" "sources;android-24" "sources;android-25" "sources;android-26" \ 147 + "sources;android-27" "sources;android-28" "sources;android-29" "sources;android-30" \ 148 + "sources;android-31" "sources;android-32" "sources;android-33" "sources;android-34" \ 149 + "system-images;android-28" \ 150 + "system-images;android-29" \ 151 + "system-images;android-30" \ 152 + "system-images;android-31" \ 153 + "system-images;android-32" \ 154 + "system-images;android-33" \ 155 + "ndk" 156 + ) 157 + 158 + for package in "''${excluded_packages[@]}"; do 159 + if [[ $installed_packages_section =~ "$package" ]]; then 160 + echo "$package package was installed, while it was excluded!" 161 + exit 1 162 + fi 163 + done 164 + 165 + touch "$out" 166 + ''; 167 + 135 168 shell-with-emulator-avdmanager-create-avd-test = pkgs.runCommand "shell-with-emulator-avdmanager-create-avd-test" { 136 169 nativeBuildInputs = [ androidSdk androidEmulator jdk ]; 137 170 } ''
+152
pkgs/development/mobile/androidenv/examples/shell-without-emulator.nix
··· 1 + { 2 + # To test your changes in androidEnv run `nix-shell android-sdk-with-emulator-shell.nix` 3 + 4 + # If you copy this example out of nixpkgs, use these lines instead of the next. 5 + # This example pins nixpkgs: https://nix.dev/tutorials/towards-reproducibility-pinning-nixpkgs.html 6 + /*nixpkgsSource ? (builtins.fetchTarball { 7 + name = "nixpkgs-20.09"; 8 + url = "https://github.com/NixOS/nixpkgs/archive/20.09.tar.gz"; 9 + sha256 = "1wg61h4gndm3vcprdcg7rc4s1v3jkm5xd7lw8r2f67w502y94gcy"; 10 + }), 11 + pkgs ? import nixpkgsSource { 12 + config.allowUnfree = true; 13 + }, 14 + */ 15 + 16 + # If you want to use the in-tree version of nixpkgs: 17 + pkgs ? import ../../../../.. { 18 + config.allowUnfree = true; 19 + } 20 + , config ? pkgs.config 21 + }: 22 + 23 + # Copy this file to your Android project. 24 + let 25 + # Declaration of versions for everything. This is useful since these 26 + # versions may be used in multiple places in this Nix expression. 27 + android = { 28 + versions = { 29 + cmdLineToolsVersion = "11.0"; 30 + platformTools = "34.0.5"; 31 + buildTools = "34.0.0"; 32 + }; 33 + platforms = [ "34" ]; 34 + }; 35 + 36 + # If you copy this example out of nixpkgs, something like this will work: 37 + /*androidEnvNixpkgs = fetchTarball { 38 + name = "androidenv"; 39 + url = "https://github.com/NixOS/nixpkgs/archive/<fill me in from Git>.tar.gz"; 40 + sha256 = "<fill me in with nix-prefetch-url --unpack>"; 41 + }; 42 + 43 + androidEnv = pkgs.callPackage "${androidEnvNixpkgs}/pkgs/development/mobile/androidenv" { 44 + inherit config pkgs; 45 + licenseAccepted = true; 46 + };*/ 47 + 48 + # Otherwise, just use the in-tree androidenv: 49 + androidEnv = pkgs.callPackage ./.. { 50 + inherit config pkgs; 51 + # You probably need to uncomment below line to express consent. 52 + # licenseAccepted = true; 53 + }; 54 + 55 + sdkArgs = { 56 + cmdLineToolsVersion = android.versions.cmdLineToolsVersion; 57 + platformToolsVersion = android.versions.platformTools; 58 + buildToolsVersions = [ android.versions.buildTools ]; 59 + platformVersions = android.platforms; 60 + includeNDK = false; 61 + includeSystemImages = false; 62 + includeEmulator = false; 63 + 64 + # Accepting more licenses declaratively: 65 + extraLicenses = [ 66 + # Already accepted for you with the global accept_license = true or 67 + # licenseAccepted = true on androidenv. 68 + # "android-sdk-license" 69 + 70 + # These aren't, but are useful for more uncommon setups. 71 + "android-sdk-preview-license" 72 + "android-googletv-license" 73 + "android-sdk-arm-dbt-license" 74 + "google-gdk-license" 75 + "intel-android-extra-license" 76 + "intel-android-sysimage-license" 77 + "mips-android-sysimage-license" 78 + ]; 79 + }; 80 + 81 + androidComposition = androidEnv.composeAndroidPackages sdkArgs; 82 + androidSdk = androidComposition.androidsdk; 83 + platformTools = androidComposition.platform-tools; 84 + jdk = pkgs.jdk; 85 + in 86 + pkgs.mkShell rec { 87 + name = "androidenv-example-without-emulator-demo"; 88 + packages = [ androidSdk platformTools jdk pkgs.android-studio ]; 89 + 90 + LANG = "C.UTF-8"; 91 + LC_ALL = "C.UTF-8"; 92 + JAVA_HOME = jdk.home; 93 + 94 + # Note: ANDROID_HOME is deprecated. Use ANDROID_SDK_ROOT. 95 + ANDROID_SDK_ROOT = "${androidSdk}/libexec/android-sdk"; 96 + 97 + shellHook = '' 98 + # Write out local.properties for Android Studio. 99 + cat <<EOF > local.properties 100 + # This file was automatically generated by nix-shell. 101 + sdk.dir=$ANDROID_SDK_ROOT 102 + EOF 103 + ''; 104 + 105 + passthru.tests = { 106 + 107 + shell-without-emulator-sdkmanager-packages-test = pkgs.runCommand "shell-without-emulator-sdkmanager-packages-test" 108 + { 109 + nativeBuildInputs = [ androidSdk jdk ]; 110 + } '' 111 + output="$(sdkmanager --list)" 112 + installed_packages_section=$(echo "''${output%%Available Packages*}" | awk 'NR>4 {print $1}') 113 + echo "installed_packages_section: ''${installed_packages_section}" 114 + 115 + packages=( 116 + "build-tools;34.0.0" "cmdline-tools;11.0" \ 117 + "patcher;v4" "platform-tools" "platforms;android-34" 118 + ) 119 + 120 + for package in "''${packages[@]}"; do 121 + if [[ ! $installed_packages_section =~ "$package" ]]; then 122 + echo "$package package was not installed." 123 + exit 1 124 + fi 125 + done 126 + 127 + touch "$out" 128 + ''; 129 + 130 + shell-without-emulator-sdkmanager-excluded-packages-test = pkgs.runCommand "shell-without-emulator-sdkmanager-excluded-packages-test" 131 + { 132 + nativeBuildInputs = [ androidSdk jdk ]; 133 + } '' 134 + output="$(sdkmanager --list)" 135 + installed_packages_section=$(echo "''${output%%Available Packages*}" | awk 'NR>4 {print $1}') 136 + 137 + excluded_packages=( 138 + "emulator" "ndk" 139 + ) 140 + 141 + for package in "''${excluded_packages[@]}"; do 142 + if [[ $installed_packages_section =~ "$package" ]]; then 143 + echo "$package package was installed, while it was excluded!" 144 + exit 1 145 + fi 146 + done 147 + 148 + touch "$out" 149 + ''; 150 + }; 151 + } 152 +
+6 -4
pkgs/development/mobile/androidenv/test-suite.nix
··· 1 - {callPackage, lib, stdenv}: 1 + { callPackage, lib, stdenv }: 2 2 let 3 - examples-shell = callPackage ./examples/shell.nix {}; 4 - examples-shell-with-emulator = callPackage ./examples/shell-with-emulator.nix {}; 3 + examples-shell = callPackage ./examples/shell.nix { }; 4 + examples-shell-with-emulator = callPackage ./examples/shell-with-emulator.nix { }; 5 + examples-shell-without-emulator = callPackage ./examples/shell-without-emulator.nix { }; 5 6 all-tests = examples-shell.passthru.tests // 6 - examples-shell-with-emulator.passthru.tests; 7 + (examples-shell-with-emulator.passthru.tests // 8 + examples-shell-without-emulator.passthru.tests); 7 9 in 8 10 stdenv.mkDerivation { 9 11 name = "androidenv-test-suite";
+1 -1
pkgs/development/mobile/androidenv/tools.nix
··· 1 1 {deployAndroidPackage, lib, package, autoPatchelfHook, makeWrapper, os, pkgs, pkgsi686Linux, postInstall}: 2 2 3 3 deployAndroidPackage { 4 - name = "androidsdk"; 4 + name = "androidsdk-tools"; 5 5 inherit os package; 6 6 nativeBuildInputs = [ makeWrapper ] 7 7 ++ lib.optionals (os == "linux") [ autoPatchelfHook ];