Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 52 additions & 31 deletions eng/devices/android.cake
Original file line number Diff line number Diff line change
Expand Up @@ -61,17 +61,6 @@ AndroidEmulatorProcess emulatorProcess = null;

var dotnetToolPath = GetDotnetToolPath();

Setup(context =>
{
LogSetupInfo(dotnetToolPath);

PerformCleanupIfNeeded(deviceCleanupEnabled);

DetermineDeviceCharacteristics(testDevice, DefaultApiLevel);

HandleVirtualDevice(emuSettings, avdSettings, androidAvd, androidAvdImage, deviceSkin, deviceBoot);
});

Teardown(context =>
{
// For the uitest-prepare target, just leave the virtual device running
Expand All @@ -82,9 +71,24 @@ Teardown(context =>

});

Task("boot");
Task("Setup")
.Does(async () =>
{
LogSetupInfo(dotnetToolPath);

PerformCleanupIfNeeded(deviceCleanupEnabled);

DetermineDeviceCharacteristics(testDevice, DefaultApiLevel);

// The Emulator Start command seems to hang sometimes so let's only give it two minutes to complete
await HandleVirtualDevice(emuSettings, avdSettings, androidAvd, androidAvdImage, deviceSkin, deviceBoot);
});

Task("boot")
.IsDependentOn("Setup");

Task("build")
.IsDependentOn("Setup")
.WithCriteria(!string.IsNullOrEmpty(projectPath))
.Does(() =>
{
Expand All @@ -99,13 +103,15 @@ Task("test")
});

Task("uitest-build")
.IsDependentOn("Setup")
.IsDependentOn("dotnet-buildtasks")
.Does(() =>
{
ExecuteBuildUITestApp(testAppProjectPath, testDevice, binlogDirectory, configuration, targetFramework, "", dotnetToolPath);
});

Task("uitest-prepare")
.IsDependentOn("Setup")
.Does(() =>
{
ExecutePrepareUITests(projectPath, testAppProjectPath, testAppPackageName, testDevice, testResultsPath, binlogDirectory, configuration, targetFramework, "", androidVersion, dotnetToolPath, testAppInstrumentation);
Expand All @@ -119,6 +125,7 @@ Task("uitest")
});

Task("logcat")
.IsDependentOn("Setup")
.Does(() =>
{
WriteLogCat();
Expand Down Expand Up @@ -425,32 +432,46 @@ void DetermineDeviceCharacteristics(string deviceDescriptor, int defaultApiLevel
}
}

void HandleVirtualDevice(AndroidEmulatorToolSettings emuSettings, AndroidAvdManagerToolSettings avdSettings, string avdName, string avdImage, string avdSkin, bool boot)
async Task HandleVirtualDevice(AndroidEmulatorToolSettings emuSettings, AndroidAvdManagerToolSettings avdSettings, string avdName, string avdImage, string avdSkin, bool boot)
{
Information("Test Device ID: {0}", avdImage);

if (boot)
try
{
Information("Trying to boot the emulator...");
// The Emulator Start command seems to hang sometimes so let's only give it two minutes to complete
await System.Threading.Tasks.Task.Run(() =>
{
Information("Test Device ID: {0}", avdImage);

// delete the AVD first, if it exists
Information("Deleting AVD if exists: {0}...", avdName);
try { AndroidAvdDelete(avdName, avdSettings); }
catch { }
if (boot)
{
Information("Trying to boot the emulator...");

// create the new AVD
Information("Creating AVD: {0} ({1})...", avdName, avdImage);
AndroidAvdCreate(avdName, avdImage, avdSkin, force: true, settings: avdSettings);
// delete the AVD first, if it exists
Information("Deleting AVD if exists: {0}...", avdName);
try { AndroidAvdDelete(avdName, avdSettings); }
catch { }

// start the emulator
Information("Starting Emulator: {0}...", avdName);
emulatorProcess = AndroidEmulatorStart(avdName, emuSettings);
}
// create the new AVD
Information("Creating AVD: {0} ({1})...", avdName, avdImage);
AndroidAvdCreate(avdName, avdImage, avdSkin, force: true, settings: avdSettings);

if (IsCIBuild())
// start the emulator
Information("Starting Emulator: {0}...", avdName);
emulatorProcess = AndroidEmulatorStart(avdName, emuSettings);
}

if (IsCIBuild() && emulatorProcess is not null)
{
Information("Setting Logcat Values");
AdbLogcat(new AdbLogcatOptions() { Clear = true });
AdbShell("logcat -G 16M");
Information("Finished Setting Logcat Values");
}
}).WaitAsync(TimeSpan.FromMinutes(2));
}
catch(TimeoutException)
{
AdbLogcat(new AdbLogcatOptions() { Clear = true });
AdbShell("logcat -G 16M");
Error("Failed to start the Android Emulator.");
throw;
}
}

Expand Down
Loading