From da977da39eceb7c231c9a0b47c25cdef732a5ceb Mon Sep 17 00:00:00 2001 From: Hadi Date: Sat, 4 Nov 2023 10:26:19 -0400 Subject: [PATCH] androidenv: fix bugs, add new arguments, and deprecate arguments - Fix the bug in #265479 - New arguments: - configOptions - deviceName - Deprecate arguments: - enableGPU --- .../mobile/androidenv/emulate-app.nix | 37 ++++++++++++------- .../examples/shell-with-emulator.nix | 1 + 2 files changed, 25 insertions(+), 13 deletions(-) diff --git a/pkgs/development/mobile/androidenv/emulate-app.nix b/pkgs/development/mobile/androidenv/emulate-app.nix index 74e002bdd16f..e4b3af304fa9 100644 --- a/pkgs/development/mobile/androidenv/emulate-app.nix +++ b/pkgs/development/mobile/androidenv/emulate-app.nix @@ -1,16 +1,26 @@ { composeAndroidPackages, stdenv, lib, runtimeShell }: -{ name, app ? null +{ name +, app ? null , platformVersion ? "33" , abiVersion ? "armeabi-v7a" , systemImageType ? "default" -, enableGPU ? false -, extraAVDFiles ? [] +, enableGPU ? false # Enable GPU acceleration. It's deprecated, instead use `configOptions` below. +, configOptions ? ( + # List of options to add in config.ini + lib.optionalAttrs enableGPU + (lib.warn + "enableGPU argument is deprecated and will be removed; use configOptions instead" + { "hw.gpu.enabled" = "yes"; } + ) + ) +, extraAVDFiles ? [ ] , package ? null , activity ? null , androidUserHome ? null , avdHomeDir ? null # Support old variable with non-standard naming! , androidAvdHome ? avdHomeDir -, sdkExtraArgs ? {} +, deviceName ? "device" +, sdkExtraArgs ? { } , androidAvdFlags ? null , androidEmulatorFlags ? null }: @@ -99,27 +109,28 @@ stdenv.mkDerivation { export ANDROID_SERIAL="emulator-$port" # Create a virtual android device for testing if it does not exist - if [ "$(${sdk}/bin/avdmanager list avd | grep 'Name: device')" = "" ] + if [ "$(${sdk}/bin/avdmanager list avd | grep 'Name: ${deviceName}')" = "" ] then # Create a virtual android device - yes "" | ${sdk}/bin/avdmanager create avd --force -n device -k "system-images;android-${platformVersion};${systemImageType};${abiVersion}" -p $ANDROID_AVD_HOME $NIX_ANDROID_AVD_FLAGS + yes "" | ${sdk}/bin/avdmanager create avd --force -n ${deviceName} -k "system-images;android-${platformVersion};${systemImageType};${abiVersion}" -p $ANDROID_AVD_HOME/${deviceName}.avd $NIX_ANDROID_AVD_FLAGS - ${lib.optionalString enableGPU '' - # Enable GPU acceleration - echo "hw.gpu.enabled=yes" >> $ANDROID_AVD_HOME/device.avd/config.ini - ''} + ${builtins.concatStringsSep "\n" ( + lib.mapAttrsToList (configKey: configValue: '' + echo "${configKey} = ${configValue}" >> $ANDROID_AVD_HOME/${deviceName}.avd/config.ini + '') configOptions + )} ${lib.concatMapStrings (extraAVDFile: '' - ln -sf ${extraAVDFile} $ANDROID_AVD_HOME/device.avd + ln -sf ${extraAVDFile} $ANDROID_AVD_HOME/${deviceName}.avd '') extraAVDFiles} fi # Launch the emulator echo "\nLaunch the emulator" - $ANDROID_SDK_ROOT/emulator/emulator -avd device -no-boot-anim -port $port $NIX_ANDROID_EMULATOR_FLAGS & + $ANDROID_SDK_ROOT/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 device and the package manager is ready..." >&2 + echo "Waiting until the emulator has booted the ${deviceName} and the package manager is ready..." >&2 ${sdk}/libexec/android-sdk/platform-tools/adb -s emulator-$port wait-for-device diff --git a/pkgs/development/mobile/androidenv/examples/shell-with-emulator.nix b/pkgs/development/mobile/androidenv/examples/shell-with-emulator.nix index 4cee79824a6b..3c08887eb5be 100644 --- a/pkgs/development/mobile/androidenv/examples/shell-with-emulator.nix +++ b/pkgs/development/mobile/androidenv/examples/shell-with-emulator.nix @@ -78,6 +78,7 @@ let androidComposition = androidEnv.composeAndroidPackages sdkArgs; androidEmulator = androidEnv.emulateApp { name = "android-sdk-emulator-demo"; + configOptions = { "hw.keyboard" = "yes"; }; sdkExtraArgs = sdkArgs; }; androidSdk = androidComposition.androidsdk;