@@ -35,55 +35,64 @@ const EMULATOR_BOOT_TIMEOUT_SECONDS = 600;
3535/**
3636 * Creates and launches a new AVD instance with the specified configurations.
3737 */
38- function launchEmulator ( apiLevel , target , arch , profile , cores , ramSize , sdcardPathOrSize , avdName , forceAvdCreation , emulatorOptions , disableAnimations , disableSpellChecker , disableLinuxHardwareAcceleration , enableHardwareKeyboard ) {
38+ function launchEmulator ( apiLevel , target , arch , profile , cores , ramSize , sdcardPathOrSize , diskSize , avdName , forceAvdCreation , emulatorOptions , disableAnimations , disableSpellChecker , disableLinuxHardwareAcceleration , enableHardwareKeyboard ) {
3939 return __awaiter ( this , void 0 , void 0 , function * ( ) {
40- // create a new AVD if AVD directory does not already exist or forceAvdCreation is true
41- const avdPath = `${ process . env . ANDROID_AVD_HOME } /${ avdName } .avd` ;
42- if ( ! fs . existsSync ( avdPath ) || forceAvdCreation ) {
43- const profileOption = profile . trim ( ) !== '' ? `--device '${ profile } '` : '' ;
44- const sdcardPathOrSizeOption = sdcardPathOrSize . trim ( ) !== '' ? `--sdcard '${ sdcardPathOrSize } '` : '' ;
45- console . log ( `Creating AVD.` ) ;
46- yield exec . exec ( `sh -c \\"echo no | avdmanager create avd --force -n "${ avdName } " --abi '${ target } /${ arch } ' --package 'system-images;android-${ apiLevel } ;${ target } ;${ arch } ' ${ profileOption } ${ sdcardPathOrSizeOption } "` ) ;
47- }
48- if ( cores ) {
49- yield exec . exec ( `sh -c \\"printf 'hw.cpu.ncore=${ cores } \n' >> ${ process . env . ANDROID_AVD_HOME } /"${ avdName } ".avd"/config.ini` ) ;
50- }
51- if ( ramSize ) {
52- yield exec . exec ( `sh -c \\"printf 'hw.ramSize=${ ramSize } \n' >> ${ process . env . ANDROID_AVD_HOME } /"${ avdName } ".avd"/config.ini` ) ;
53- }
54- if ( enableHardwareKeyboard ) {
55- yield exec . exec ( `sh -c \\"printf 'hw.keyboard=yes\n' >> ${ process . env . ANDROID_AVD_HOME } /"${ avdName } ".avd"/config.ini` ) ;
56- }
57- //turn off hardware acceleration on Linux
58- if ( process . platform === 'linux' && disableLinuxHardwareAcceleration ) {
59- console . log ( 'Disabling Linux hardware acceleration.' ) ;
60- emulatorOptions += ' -accel off' ;
61- }
62- // start emulator
63- console . log ( 'Starting emulator.' ) ;
64- yield exec . exec ( `sh -c \\"${ process . env . ANDROID_SDK_ROOT } /emulator/emulator -avd "${ avdName } " ${ emulatorOptions } &"` , [ ] , {
65- listeners : {
66- stderr : ( data ) => {
67- if ( data . toString ( ) . includes ( 'invalid command-line parameter' ) ) {
68- throw new Error ( data . toString ( ) ) ;
40+ try {
41+ console . log ( `::group::Launch Emulator` ) ;
42+ // create a new AVD if AVD directory does not already exist or forceAvdCreation is true
43+ const avdPath = `${ process . env . ANDROID_AVD_HOME } /${ avdName } .avd` ;
44+ if ( ! fs . existsSync ( avdPath ) || forceAvdCreation ) {
45+ const profileOption = profile . trim ( ) !== '' ? `--device '${ profile } '` : '' ;
46+ const sdcardPathOrSizeOption = sdcardPathOrSize . trim ( ) !== '' ? `--sdcard '${ sdcardPathOrSize } '` : '' ;
47+ console . log ( `Creating AVD.` ) ;
48+ yield exec . exec ( `sh -c \\"echo no | avdmanager create avd --force -n "${ avdName } " --abi '${ target } /${ arch } ' --package 'system-images;android-${ apiLevel } ;${ target } ;${ arch } ' ${ profileOption } ${ sdcardPathOrSizeOption } "` ) ;
49+ }
50+ if ( cores ) {
51+ yield exec . exec ( `sh -c \\"printf 'hw.cpu.ncore=${ cores } \n' >> ${ process . env . ANDROID_AVD_HOME } /"${ avdName } ".avd"/config.ini` ) ;
52+ }
53+ if ( ramSize ) {
54+ yield exec . exec ( `sh -c \\"printf 'hw.ramSize=${ ramSize } \n' >> ${ process . env . ANDROID_AVD_HOME } /"${ avdName } ".avd"/config.ini` ) ;
55+ }
56+ if ( enableHardwareKeyboard ) {
57+ yield exec . exec ( `sh -c \\"printf 'hw.keyboard=yes\n' >> ${ process . env . ANDROID_AVD_HOME } /"${ avdName } ".avd"/config.ini` ) ;
58+ }
59+ if ( diskSize ) {
60+ yield exec . exec ( `sh -c \\"printf 'disk.dataPartition.size=${ diskSize } \n' >> ${ process . env . ANDROID_AVD_HOME } /"${ avdName } ".avd"/config.ini` ) ;
61+ }
62+ //turn off hardware acceleration on Linux
63+ if ( process . platform === 'linux' && disableLinuxHardwareAcceleration ) {
64+ console . log ( 'Disabling Linux hardware acceleration.' ) ;
65+ emulatorOptions += ' -accel off' ;
66+ }
67+ // start emulator
68+ console . log ( 'Starting emulator.' ) ;
69+ yield exec . exec ( `sh -c \\"${ process . env . ANDROID_SDK_ROOT } /emulator/emulator -avd "${ avdName } " ${ emulatorOptions } &"` , [ ] , {
70+ listeners : {
71+ stderr : ( data ) => {
72+ if ( data . toString ( ) . includes ( 'invalid command-line parameter' ) ) {
73+ throw new Error ( data . toString ( ) ) ;
74+ }
6975 }
7076 }
77+ } ) ;
78+ // wait for emulator to complete booting
79+ yield waitForDevice ( ) ;
80+ yield exec . exec ( `adb shell input keyevent 82` ) ;
81+ if ( disableAnimations ) {
82+ console . log ( 'Disabling animations.' ) ;
83+ yield exec . exec ( `adb shell settings put global window_animation_scale 0.0` ) ;
84+ yield exec . exec ( `adb shell settings put global transition_animation_scale 0.0` ) ;
85+ yield exec . exec ( `adb shell settings put global animator_duration_scale 0.0` ) ;
86+ }
87+ if ( disableSpellChecker ) {
88+ yield exec . exec ( `adb shell settings put secure spell_checker_enabled 0` ) ;
89+ }
90+ if ( enableHardwareKeyboard ) {
91+ yield exec . exec ( `adb shell settings put secure show_ime_with_hard_keyboard 0` ) ;
7192 }
72- } ) ;
73- // wait for emulator to complete booting
74- yield waitForDevice ( ) ;
75- yield exec . exec ( `adb shell input keyevent 82` ) ;
76- if ( disableAnimations ) {
77- console . log ( 'Disabling animations.' ) ;
78- yield exec . exec ( `adb shell settings put global window_animation_scale 0.0` ) ;
79- yield exec . exec ( `adb shell settings put global transition_animation_scale 0.0` ) ;
80- yield exec . exec ( `adb shell settings put global animator_duration_scale 0.0` ) ;
81- }
82- if ( disableSpellChecker ) {
83- yield exec . exec ( `adb shell settings put secure spell_checker_enabled 0` ) ;
8493 }
85- if ( enableHardwareKeyboard ) {
86- yield exec . exec ( `adb shell settings put secure show_ime_with_hard_keyboard 0 `) ;
94+ finally {
95+ console . log ( `::endgroup:: `) ;
8796 }
8897 } ) ;
8998}
@@ -94,11 +103,15 @@ exports.launchEmulator = launchEmulator;
94103function killEmulator ( ) {
95104 return __awaiter ( this , void 0 , void 0 , function * ( ) {
96105 try {
106+ console . log ( `::group::Terminate Emulator` ) ;
97107 yield exec . exec ( `adb -s emulator-5554 emu kill` ) ;
98108 }
99109 catch ( error ) {
100110 console . log ( error . message ) ;
101111 }
112+ finally {
113+ console . log ( `::endgroup::` ) ;
114+ }
102115 } ) ;
103116}
104117exports . killEmulator = killEmulator ;
0 commit comments