Change:
When you run it creates an AVD named if it doesn't exist. The problem is that it creates is in a wrong directory! Assume then run and then close the created and launched emulator, and now open the Android Studio to see the problem then open the "Device Manager" to see ! No corrupted file in Android Studio! I'll create a PR soon.
Fixed by I assume.

Discussion:
{ composeAndroidPackages, stdenv, lib, runtimeShell }: <del> { name, app ? null </del> <ins> { name , app ? null </ins> , platformVersion ? "33" , abiVersion ? "armeabi-v7a" , systemImageType ? "default" <del> , enableGPU ? false , extraAVDFiles ? [] </del> <ins> , 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 ? [ ] </ins> , package ? null , activity ? null , androidUserHome ? null , avdHomeDir ? null # Support old variable with non-standard naming! , androidAvdHome ? avdHomeDir <del> , sdkExtraArgs ? {} </del> <ins> , deviceName ? "device" , sdkExtraArgs ? { } </ins> , androidAvdFlags ? null , androidEmulatorFlags ? null }:

export ANDROID_SERIAL="emulator-$port" # Create a virtual android device for testing if it does not exist <del> if [ "$(${sdk}/bin/avdmanager list avd | grep 'Name: device')" = "" ] </del> <ins> if [ "$(${sdk}/bin/avdmanager list avd | grep 'Name: ${deviceName}')" = "" ] </ins> then # Create a virtual android device <del> yes "" | ${sdk}/bin/avdmanager create avd --force -n device -k "system-images;android-${platformVersion};${systemImageType};${abiVersion}" -p $ANDROID_AVD_HOME $NIX_ANDROID_AVD_FLAGS </del> <ins> 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 </ins> <del> ${lib.optionalString enableGPU '' # Enable GPU acceleration echo "hw.gpu.enabled=yes" >> $ANDROID_AVD_HOME/device.avd/config.ini ''} </del> <ins> ${builtins.concatStringsSep "n" ( lib.mapAttrsToList (configKey: configValue: '' echo "${configKey} = ${configValue}" >> $ANDROID_AVD_HOME/${deviceName}.avd/config.ini '') configOptions )} </ins> ${lib.concatMapStrings (extraAVDFile: '' <del> ln -sf ${extraAVDFile} $ANDROID_AVD_HOME/device.avd </del> <ins> ln -sf ${extraAVDFile} $ANDROID_AVD_HOME/${deviceName}.avd </ins> '') extraAVDFiles} fi # Launch the emulator echo "nLaunch the emulator" <del> $ANDROID_SDK_ROOT/emulator/emulator -avd device -no-boot-anim -port $port $NIX_ANDROID_EMULATOR_FLAGS & </del> <ins> $ANDROID_SDK_ROOT/emulator/emulator -avd ${deviceName} -no-boot-anim -port $port $NIX_ANDROID_EMULATOR_FLAGS & </ins> # Wait until the device has completely booted <del> echo "Waiting until the emulator has booted the device and the package manager is ready..." >&2 </del> <ins> echo "Waiting until the emulator has booted the ${deviceName} and the package manager is ready..." >&2 </ins> ${sdk}/libexec/android-sdk/platform-tools/adb -s emulator-$port wait-for-device

androidComposition = androidEnv.composeAndroidPackages sdkArgs; androidEmulator = androidEnv.emulateApp { name = "android-sdk-emulator-demo"; <ins> configOptions = { "hw.keyboard" = "yes"; }; </ins> sdkExtraArgs = sdkArgs; }; androidSdk = androidComposition.androidsdk;