about summary refs log tree commit diff
path: root/pkgs/development/mobile
diff options
context:
space:
mode:
authorHadi <hadilq.dev@gmail.com>2023-11-04 10:26:19 -0400
committerHadi <hadilq.dev@gmail.com>2023-12-15 16:20:39 -0500
commitda977da39eceb7c231c9a0b47c25cdef732a5ceb (patch)
treea6a6a97be68d95234bd1213d6c19daa26a49f0c7 /pkgs/development/mobile
parentc71de1b26252bbcabd49f736996cdcc64eeb386c (diff)
androidenv: fix bugs, add new arguments, and deprecate arguments
- Fix the bug in #265479
- New arguments:
  - configOptions
  - deviceName
- Deprecate arguments:
  - enableGPU
Diffstat (limited to 'pkgs/development/mobile')
-rw-r--r--pkgs/development/mobile/androidenv/emulate-app.nix37
-rw-r--r--pkgs/development/mobile/androidenv/examples/shell-with-emulator.nix1
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 74e002bdd16f3..e4b3af304fa91 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 4cee79824a6be..3c08887eb5be1 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;