mirror of
https://github.com/NixOS/nixpkgs.git
synced 2024-11-25 16:33:15 +00:00
androidenv: fix bugs, add new arguments, and deprecate arguments
- Fix the bug in #265479 - New arguments: - configOptions - deviceName - Deprecate arguments: - enableGPU
This commit is contained in:
parent
c71de1b262
commit
da977da39e
@ -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
|
||||
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user