Merge pull request from hadilq/androidenv-fix-avd-directory

androidenv fix avd directory, and making config options more available
This commit is contained in:
Peder Bergebakken Sundt 2023-12-17 16:38:15 +01:00 committed by GitHub
commit f82c0d5417
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 13 deletions
pkgs/development/mobile/androidenv

View file

@ -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

View file

@ -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;