@@ -61,17 +61,6 @@ AndroidEmulatorProcess emulatorProcess = null;
6161
6262var dotnetToolPath = GetDotnetToolPath ( ) ;
6363
64- Setup ( context =>
65- {
66- LogSetupInfo ( dotnetToolPath ) ;
67-
68- PerformCleanupIfNeeded ( deviceCleanupEnabled ) ;
69-
70- DetermineDeviceCharacteristics ( testDevice , DefaultApiLevel ) ;
71-
72- HandleVirtualDevice ( emuSettings , avdSettings , androidAvd , androidAvdImage , deviceSkin , deviceBoot ) ;
73- } ) ;
74-
7564Teardown ( context =>
7665{
7766 // For the uitest-prepare target, just leave the virtual device running
@@ -82,9 +71,24 @@ Teardown(context =>
8271
8372} ) ;
8473
85- Task ( "boot" ) ;
74+ Task ( "Setup" )
75+ . Does ( async ( ) =>
76+ {
77+ LogSetupInfo ( dotnetToolPath ) ;
78+
79+ PerformCleanupIfNeeded ( deviceCleanupEnabled ) ;
80+
81+ DetermineDeviceCharacteristics ( testDevice , DefaultApiLevel ) ;
82+
83+ // The Emulator Start command seems to hang sometimes so let's only give it two minutes to complete
84+ await HandleVirtualDevice ( emuSettings , avdSettings , androidAvd , androidAvdImage , deviceSkin , deviceBoot ) ;
85+ } ) ;
86+
87+ Task ( "boot" )
88+ . IsDependentOn ( "Setup" ) ;
8689
8790Task ( "build" )
91+ . IsDependentOn ( "Setup" )
8892 . WithCriteria ( ! string . IsNullOrEmpty ( projectPath ) )
8993 . Does ( ( ) =>
9094 {
@@ -99,13 +103,15 @@ Task("test")
99103 } ) ;
100104
101105Task ( "uitest-build" )
106+ . IsDependentOn ( "Setup" )
102107 . IsDependentOn ( "dotnet-buildtasks" )
103108 . Does ( ( ) =>
104109 {
105110 ExecuteBuildUITestApp ( testAppProjectPath , testDevice , binlogDirectory , configuration , targetFramework , "" , dotnetToolPath ) ;
106111 } ) ;
107112
108113Task ( "uitest-prepare" )
114+ . IsDependentOn ( "Setup" )
109115 . Does ( ( ) =>
110116 {
111117 ExecutePrepareUITests ( projectPath , testAppProjectPath , testAppPackageName , testDevice , testResultsPath , binlogDirectory , configuration , targetFramework , "" , androidVersion , dotnetToolPath , testAppInstrumentation ) ;
@@ -119,6 +125,7 @@ Task("uitest")
119125 } ) ;
120126
121127Task ( "logcat" )
128+ . IsDependentOn ( "Setup" )
122129 . Does ( ( ) =>
123130{
124131 WriteLogCat ( ) ;
@@ -425,32 +432,45 @@ void DetermineDeviceCharacteristics(string deviceDescriptor, int defaultApiLevel
425432 }
426433}
427434
428- void HandleVirtualDevice ( AndroidEmulatorToolSettings emuSettings , AndroidAvdManagerToolSettings avdSettings , string avdName , string avdImage , string avdSkin , bool boot )
435+ async Task HandleVirtualDevice ( AndroidEmulatorToolSettings emuSettings , AndroidAvdManagerToolSettings avdSettings , string avdName , string avdImage , string avdSkin , bool boot )
429436{
430- Information ( "Test Device ID: {0}" , avdImage ) ;
431-
432- if ( boot )
437+ try
433438 {
434- Information ( "Trying to boot the emulator..." ) ;
439+ // The Emulator Start command seems to hang sometimes so let's only give it two minutes to complete
440+ await System . Threading . Tasks . Task . Run ( ( ) =>
441+ {
442+ Information ( "Test Device ID: {0}" , avdImage ) ;
435443
436- // delete the AVD first, if it exists
437- Information ( "Deleting AVD if exists: {0}..." , avdName ) ;
438- try { AndroidAvdDelete ( avdName , avdSettings ) ; }
439- catch { }
444+ if ( boot )
445+ {
446+ Information ( "Trying to boot the emulator..." ) ;
440447
441- // create the new AVD
442- Information ( "Creating AVD: {0} ({1})..." , avdName , avdImage ) ;
443- AndroidAvdCreate ( avdName , avdImage , avdSkin , force : true , settings : avdSettings ) ;
448+ // delete the AVD first, if it exists
449+ Information ( "Deleting AVD if exists: {0}..." , avdName ) ;
450+ try { AndroidAvdDelete ( avdName , avdSettings ) ; }
451+ catch { }
444452
445- // start the emulator
446- Information ( "Starting Emulator: {0}..." , avdName ) ;
447- emulatorProcess = AndroidEmulatorStart ( avdName , emuSettings ) ;
448- }
453+ // create the new AVD
454+ Information ( "Creating AVD: {0} ({1})..." , avdName , avdImage ) ;
455+ AndroidAvdCreate ( avdName , avdImage , avdSkin , force : true , settings : avdSettings ) ;
449456
450- if ( IsCIBuild ( ) )
457+ // start the emulator
458+ Information ( "Starting Emulator: {0}..." , avdName ) ;
459+ emulatorProcess = AndroidEmulatorStart ( avdName , emuSettings ) ;
460+ }
461+
462+ if ( IsCIBuild ( ) )
463+ {
464+ Information ( "Setting Logcat Values" ) ;
465+ AdbLogcat ( new AdbLogcatOptions ( ) { Clear = true } ) ;
466+ AdbShell ( "logcat -G 16M" ) ;
467+ }
468+ } ) . WaitAsync ( TimeSpan . FromMinutes ( 2 ) ) ;
469+ }
470+ catch ( TimeoutException )
451471 {
452- AdbLogcat ( new AdbLogcatOptions ( ) { Clear = true } ) ;
453- AdbShell ( "logcat -G 16M" ) ;
472+ Error ( "Failed to start the Android Emulator." ) ;
473+ throw ;
454474 }
455475}
456476
0 commit comments