-
Notifications
You must be signed in to change notification settings - Fork 1.8k
/
Copy pathandroid.cake
671 lines (564 loc) · 20.6 KB
/
android.cake
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
#addin nuget:?package=Cake.Android.Adb&version=3.2.0
#addin nuget:?package=Cake.Android.AvdManager&version=2.2.0
#load "./uitests-shared.cake"
const int DefaultApiLevel = 30;
const int EmulatorStartProcessTimeoutSeconds = 1 * 60;
const int EmulatorBootTimeoutSeconds = 2 * 60;
Information("Local Dotnet: {0}", localDotnet);
if (EnvironmentVariable("JAVA_HOME") == null)
{
throw new Exception("JAVA_HOME environment variable isn't set. Set it to your JDK installation (e.g. \"C:\\Program Files (x86)\\Android\\openjdk\\jdk-17.0.8.101-hotspot\\bin\").");
}
string DEFAULT_ANDROID_PROJECT = "../../src/Controls/tests/TestCases.Android.Tests/Controls.TestCases.Android.Tests.csproj";
var projectPath = Argument("project", EnvironmentVariable("ANDROID_TEST_PROJECT") ?? "");
var testDevice = Argument("device", EnvironmentVariable("ANDROID_TEST_DEVICE") ?? $"android-emulator-64_{DefaultApiLevel}");
var targetFramework = Argument("tfm", EnvironmentVariable("TARGET_FRAMEWORK") ?? $"{DotnetVersion}-android");
var binlogArg = Argument("binlog", EnvironmentVariable("ANDROID_TEST_BINLOG") ?? "");
var testApp = Argument("app", EnvironmentVariable("ANDROID_TEST_APP") ?? "");
var testAppProjectPath = Argument("appproject", EnvironmentVariable("ANDROID_TEST_APP_PROJECT") ?? DEFAULT_APP_PROJECT);
var testAppPackageName = Argument("package", EnvironmentVariable("ANDROID_TEST_APP_PACKAGE_NAME") ?? "");
var testAppInstrumentation = Argument("instrumentation", EnvironmentVariable("ANDROID_TEST_APP_INSTRUMENTATION") ?? "");
var testResultsPath = Argument("results", EnvironmentVariable("ANDROID_TEST_RESULTS") ?? GetTestResultsDirectory()?.FullPath);
var deviceCleanupEnabled = Argument("cleanup", true);
// Device details
var deviceSkin = Argument("skin", EnvironmentVariable("ANDROID_TEST_SKIN") ?? "Nexus 5X");
var androidAvd = "";
var androidAvdImage = "";
var deviceArch = "";
var androidVersion = Argument("apiversion", EnvironmentVariable("ANDROID_PLATFORM_VERSION") ?? DefaultApiLevel.ToString());
// Directory setup
var binlogDirectory = DetermineBinlogDirectory(projectPath, binlogArg)?.FullPath;
string DEVICE_UDID = "";
string DEVICE_VERSION = "";
string DEVICE_NAME = "";
string DEVICE_OS = "";
// Android SDK setup
Information("ANDROID_SDK_ROOT: {0}", EnvironmentVariable("ANDROID_SDK_ROOT"));
Information("ANDROID_HOME: {0}", EnvironmentVariable("ANDROID_HOME"));
var androidSdkRoot = GetAndroidSDKPath();
SetAndroidEnvironmentVariables(androidSdkRoot);
Information("Android SDK Root: {0}", androidSdkRoot);
Information("Project File: {0}", projectPath);
Information("Build Binary Log (binlog): {0}", binlogDirectory);
Information("Build Configuration: {0}", configuration);
Information("Build Target Framework: {0}", targetFramework);
var avdSettings = new AndroidAvdManagerToolSettings { SdkRoot = androidSdkRoot };
var adbSettings = new AdbToolSettings { SdkRoot = androidSdkRoot };
var emuSettings = new AndroidEmulatorToolSettings { SdkRoot = androidSdkRoot };
emuSettings = AdjustEmulatorSettingsForCI(emuSettings);
AndroidEmulatorProcess emulatorProcess = null;
var dotnetToolPath = GetDotnetToolPath();
LogSetupInfo(dotnetToolPath);
Teardown(context =>
{
// For the uitest-prepare target, just leave the virtual device running
if (!string.Equals(TARGET, "uitest-prepare", StringComparison.OrdinalIgnoreCase))
{
CleanUpVirtualDevice(emulatorProcess, avdSettings);
}
});
Task("connectToDevice")
.Does(async () =>
{
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("connectToDevice");
Task("buildOnly")
.WithCriteria(!string.IsNullOrEmpty(projectPath))
.Does(() =>
{
ExecuteBuild(projectPath, testDevice, binlogDirectory, configuration, targetFramework, dotnetToolPath);
});
Task("testOnly")
.IsDependentOn("connectToDevice")
.WithCriteria(!string.IsNullOrEmpty(projectPath))
.Does(() =>
{
ExecuteTests(projectPath, testDevice, testAppPackageName, testResultsPath, configuration, targetFramework, adbSettings, dotnetToolPath, deviceBootWait, testAppInstrumentation);
});
Task("build")
.IsDependentOn("buildOnly");
Task("test")
.IsDependentOn("buildOnly")
.IsDependentOn("testOnly");
Task("buildAndTest")
.IsDependentOn("buildOnly")
.IsDependentOn("testOnly");
Task("uitest-prepare")
.IsDependentOn("connectToDevice")
.Does(() =>
{
ExecutePrepareUITests(projectPath, testAppProjectPath, testAppPackageName, testDevice, testResultsPath, binlogDirectory, configuration, targetFramework, "", androidVersion, dotnetToolPath, testAppInstrumentation);
});
Task("uitest")
.IsDependentOn("uitest-prepare")
.Does(() =>
{
ExecuteUITests(projectPath, testAppProjectPath, testAppPackageName, testDevice, testResultsPath, binlogDirectory, configuration, targetFramework, "", androidVersion, dotnetToolPath, testAppInstrumentation);
});
Task("logcat")
.IsDependentOn("connectToDevice")
.Does(() =>
{
WriteLogCat();
});
RunTarget(TARGET);
void ExecuteBuild(string project, string device, string binDir, string config, string tfm, string toolPath)
{
var projectName = System.IO.Path.GetFileNameWithoutExtension(project);
var binlog = $"{binDir}/{projectName}-{config}-android.binlog";
DotNetBuild(project, new DotNetBuildSettings
{
Configuration = config,
Framework = tfm,
MSBuildSettings = new DotNetMSBuildSettings
{
MaxCpuCount = 0
},
ToolPath = toolPath,
ArgumentCustomization = args => args
.Append("/p:EmbedAssembliesIntoApk=true")
.Append("/bl:" + binlog)
});
}
void ExecuteTests(string project, string device, string appPackageName, string resultsDir, string config, string tfm, AdbToolSettings adbSettings, string toolPath, bool waitDevice, string instrumentation)
{
CleanResults(resultsDir);
var testApp = GetTestApplications(project, device, config, tfm, "").FirstOrDefault();
if (string.IsNullOrEmpty(appPackageName))
{
var appFile = new FilePath(testApp);
appFile = appFile.GetFilenameWithoutExtension();
appPackageName = appFile.FullPath.Replace("-Signed", "");
}
if (string.IsNullOrEmpty(instrumentation))
{
instrumentation = appPackageName + ".TestInstrumentation";
}
Information("Test App: {0}", testApp);
Information("Test App Package Name: {0}", appPackageName);
Information("Test Results Directory: {0}", resultsDir);
PrepareDevice(waitDevice);
var settings = new DotNetToolSettings
{
DiagnosticOutput = true,
ArgumentCustomization = args => args.Append("run xharness android test " +
$"--app=\"{testApp}\" " +
$"--package-name=\"{appPackageName}\" " +
$"--instrumentation=\"{instrumentation}\" " +
$"--device-arch=\"{deviceArch}\" " +
$"--output-directory=\"{resultsDir}\" " +
$"--verbosity=\"Debug\" ")
};
bool testsFailed = true;
try
{
DotNetTool("tool", settings);
testsFailed = false;
}
finally
{
if (testsFailed)
{
// uncomment if you want to copy the test app to the results directory for any reason
// CopyFile(testApp, new DirectoryPath(resultsDir).CombineWithFilePath(new FilePath(testApp).GetFilename()));
}
HandleTestResults(resultsDir, testsFailed, false);
}
Information("Testing completed.");
}
void ExecutePrepareUITests(string project, string app, string appPackageName, string device, string resultsDir, string binDir, string config, string tfm, string rid, string ver, string toolPath, string instrumentation)
{
string platform = "android";
Information("Preparing UI Tests...");
var testApp = GetTestApplications(app, device, config, tfm, "").FirstOrDefault();
if (string.IsNullOrEmpty(testApp))
{
throw new Exception("UI Test application path not specified.");
}
if (string.IsNullOrEmpty(appPackageName))
{
var appFile = new FilePath(testApp);
appFile = appFile.GetFilenameWithoutExtension();
appPackageName = appFile.FullPath.Replace("-Signed", "");
}
if (string.IsNullOrEmpty(instrumentation))
{
instrumentation = appPackageName + ".TestInstrumentation";
}
Information("Test App: {0}", testApp);
Information("Test App Package Name: {0}", appPackageName);
Information("Test Results Directory: {0}", resultsDir);
Information($"Testing Device: {device}");
Information($"Testing App Project: {app}");
Information($"Testing App: {testApp}");
Information($"Results Directory: {resultsDir}");
InstallApk(testApp, appPackageName, resultsDir, deviceSkin);
}
void ExecuteUITests(string project, string app, string appPackageName, string device, string resultsDir, string binDir, string config, string tfm, string rid, string ver, string toolPath, string instrumentation)
{
string platform = "android";
Information("Build UITests project {0}", project);
var name = System.IO.Path.GetFileNameWithoutExtension(project);
var binlog = $"{binDir}/{name}-{config}-{platform}.binlog";
var resultsFileName = SanitizeTestResultsFilename($"{name}-{config}-{platform}-{testFilter}");
var appiumLog = $"{binDir}/appium_{platform}_{resultsFileName}.log";
DotNetBuild(project, new DotNetBuildSettings
{
Configuration = config,
ToolPath = toolPath,
ArgumentCustomization = args => args
.Append("/p:ExtraDefineConstants=ANDROID")
.Append("/bl:" + binlog)
});
SetEnvironmentVariable("APPIUM_LOG_FILE", appiumLog);
int numOfRetries = 0;
if (IsCIBuild())
numOfRetries = 1;
Information("Run UITests project {0}", project);
for(int retryCount = 0; retryCount <= numOfRetries; retryCount++)
{
try
{
Information("Retry UITests run Count: {0}", retryCount);
RunTestWithLocalDotNet(project, config, pathDotnet: toolPath, noBuild: true, resultsFileNameWithoutExtension: resultsFileName);
break;
}
catch(Exception)
{
if (retryCount == numOfRetries)
{
WriteLogCat();
throw;
}
}
}
Information("UI Tests completed.");
}
// Helper methods
void SetAndroidEnvironmentVariables(string sdkRoot)
{
// Set up Android SDK environment variables and paths
string[] paths = {
$"{sdkRoot}/cmdline-tools/latest/bin",
$"{sdkRoot}/cmdline-tools/17.0/bin",
$"{sdkRoot}/platform-tools",
$"{sdkRoot}/emulator" };
foreach (var path in paths)
{
SetEnvironmentVariable("PATH", path, prepend: true);
}
foreach (var folder in GetDirectories($"{sdkRoot}/cmdline-tools/*"))
{
Information("Found cmdline-tools folders: {0}", folder.FullPath);
}
}
AndroidEmulatorToolSettings AdjustEmulatorSettingsForCI(AndroidEmulatorToolSettings settings)
{
if (IsCIBuild())
{
var gpu = IsRunningOnLinux() ? "-gpu swiftshader_indirect" : "";
settings.ArgumentCustomization = args => args
.Append(gpu)
.Append("-no-window")
.Append("-no-snapshot")
.Append("-no-audio")
.Append("-no-boot-anim");
}
return settings;
}
void DetermineDeviceCharacteristics(string deviceDescriptor, int defaultApiLevel)
{
var isArm64 = System.Runtime.InteropServices.RuntimeInformation.OSArchitecture == System.Runtime.InteropServices.Architecture.Arm64;
var working = deviceDescriptor.Trim().ToLower();
var emulator = true;
var api = defaultApiLevel;
// version
if (working.IndexOf("_") is int idx && idx > 0)
{
api = int.Parse(working.Substring(idx + 1));
working = working.Substring(0, idx);
}
var parts = working.Split('-');
// os
if (parts[0] != "android")
throw new Exception("Unexpected platform (expected: android) in device: " + deviceDescriptor);
// device/emulator
Information("Create for: {0}", parts[1]);
if (parts[1] == "device")
emulator = false;
else if (parts[1] != "emulator" && parts[1] != "simulator")
throw new Exception("Unexpected device type (expected: device|emulator) in device: " + deviceDescriptor);
// arch/bits
Information("Host OS System Arch: {0}", System.Runtime.InteropServices.RuntimeInformation.OSArchitecture);
Information("Host Processor System Arch: {0}", System.Runtime.InteropServices.RuntimeInformation.ProcessArchitecture);
if (parts[2] == "32")
{
if (emulator)
deviceArch = "x86";
else
deviceArch = "armeabi-v7a";
}
else if (parts[2] == "64")
{
if (isArm64)
deviceArch = "arm64-v8a";
else if (emulator)
deviceArch = "x86_64";
else
deviceArch = "arm64-v8a";
}
var sdk = api >= 27 ? "google_apis_playstore" : "google_apis";
if (api == 27 && deviceArch == "x86_64")
sdk = "default";
if (api == 27 && deviceArch == "arm64-v8a")
sdk = "google_apis";
androidAvd = $"Emulator_{api}";
androidAvdImage = $"system-images;android-{api};{sdk};{deviceArch}";
Information("Going to run image: {0}", androidAvdImage);
// we are not using a virtual device, so quit
if (!emulator)
{
Information("Not using a virtual device, skipping... and getting devices ");
GetDevices(api.ToString(), dotnetToolPath);
return;
}
}
async Task HandleVirtualDevice(AndroidEmulatorToolSettings emuSettings, AndroidAvdManagerToolSettings avdSettings, string avdName, string avdImage, string avdSkin, bool boot)
{
try
{
// 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);
if (boot)
{
Information("Trying to boot the emulator...");
if (deviceCreate)
{
// delete the AVD first, if it exists
Information("Deleting AVD if exists: {0}...", avdName);
try { AndroidAvdDelete(avdName, avdSettings); }
catch { }
// create the new AVD
Information("Creating AVD: {0} ({1})...", avdName, avdImage);
AndroidAvdCreate(avdName, avdImage, avdSkin, force: true, settings: avdSettings);
}
// start the emulator
Information("Starting Emulator: {0}...", avdName);
emulatorProcess = AndroidEmulatorStart(avdName, emuSettings);
}
}).WaitAsync(TimeSpan.FromSeconds(EmulatorStartProcessTimeoutSeconds));
}
catch (TimeoutException)
{
Error("Failed to start the Android Emulator.");
throw;
}
}
void CleanUpVirtualDevice(AndroidEmulatorProcess emulatorProcess, AndroidAvdManagerToolSettings avdSettings)
{
// no virtual device was used
if (emulatorProcess == null || !deviceBoot || targetBoot)
return;
//stop and cleanup the emulator
Information("AdbEmuKill");
AdbEmuKill(adbSettings);
System.Threading.Thread.Sleep(5000);
// kill the process if it has not already exited
Information("emulatorProcess.Kill()");
try { emulatorProcess.Kill(); }
catch { }
if (deviceCreate)
{
Information("AndroidAvdDelete");
// delete the AVD
try { AndroidAvdDelete(androidAvd, avdSettings); }
catch { }
}
}
void WriteLogCat(string filename = null)
{
if (string.IsNullOrWhiteSpace(filename))
{
var timeStamp = DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss");
filename = $"logcat_{TARGET}_{timeStamp}.log";
}
EnsureDirectoryExists(GetLogDirectory());
// I tried AdbLogcat here but the pipeline kept reporting "cannot create file"
var location = $"{GetLogDirectory()}/{filename}";
Information("Writing logcat to {0}", location);
var processSettings = new ProcessSettings();
processSettings.RedirectStandardOutput = true;
processSettings.RedirectStandardError = true;
var adb = $"{androidSdkRoot}/platform-tools/adb";
Information("Running: {0} logcat -d", adb);
processSettings.Arguments = $"logcat -d";
using (var fs = new System.IO.FileStream(location, System.IO.FileMode.Create))
using (var sw = new StreamWriter(fs))
{
processSettings.RedirectedStandardOutputHandler = (output) =>
{
sw.WriteLine(output);
return output;
};
var process = StartProcess($"{adb}", processSettings);
Information("exit code {0}", process);
}
Information("Logcat written to {0}", location);
}
void InstallApk(string testApp, string testAppPackageName, string testResultsDirectory, string skin)
{
PrepareDevice(deviceBootWait);
//install apk on the emulator or device
Information("Install with xharness: {0}", testApp);
var settings = new DotNetToolSettings
{
DiagnosticOutput = true,
ArgumentCustomization = args =>
{
args.Append("run xharness android install " +
$"--app=\"{testApp}\" " +
$"--package-name=\"{testAppPackageName}\" " +
$"--output-directory=\"{testResultsDirectory}\" " +
$"--verbosity=\"Debug\" ");
//if we specify a device we need to pass it to xharness
if (!string.IsNullOrEmpty(DEVICE_UDID))
{
args.Append($"--device-id=\"{DEVICE_UDID}\" ");
}
return args;
}
};
Information("The platform version to run tests:");
SetEnvironmentVariable("DEVICE_SKIN", skin);
if (!string.IsNullOrEmpty(DEVICE_UDID))
{
SetEnvironmentVariable("DEVICE_UDID", DEVICE_UDID);
//this needs to be translated to android 10/11 for appium
var realApi = "";
if (DEVICE_VERSION == "34ß")
{
realApi = "14";
}
if (DEVICE_VERSION == "33")
{
realApi = "13";
}
if (DEVICE_VERSION == "32" || DEVICE_VERSION == "31")
{
realApi = "12";
}
else if (DEVICE_VERSION == "30")
{
realApi = "11";
}
SetEnvironmentVariable("PLATFORM_VERSION", realApi);
}
DotNetTool("tool", settings);
}
void GetDevices(string version, string toolPath)
{
var deviceUdid = "";
var deviceName = "";
var deviceVersion = "";
var deviceOS = "";
var devices = AdbDevices(adbSettings);
foreach (var device in devices)
{
deviceUdid = device.Serial;
deviceName = device.Model;
deviceOS = device.Product;
deviceVersion = AdbShell($"getprop ro.build.version.sdk ", new AdbToolSettings { SdkRoot = androidSdkRoot, Serial = deviceUdid }).FirstOrDefault();
Information("DeviceName:{0} udid:{1} version:{2} os:{3}", deviceName, deviceUdid, deviceVersion, deviceOS);
if (version.Contains(deviceVersion.Split(".")[0]))
{
Information("We want this device: {0} {1} because it matches {2}", deviceName, deviceVersion, version);
DEVICE_UDID = deviceUdid;
DEVICE_VERSION = deviceVersion;
DEVICE_NAME = deviceName;
DEVICE_OS = deviceOS;
break;
}
}
//this will fail if there are no devices with this api attached
var settings = new DotNetToolSettings
{
DiagnosticOutput = true,
ToolPath = toolPath,
ArgumentCustomization = args => args.Append("run xharness android device " +
$"--api-version=\"{version}\" ")
};
DotNetTool("tool", settings);
}
void PrepareDevice(bool waitForBoot)
{
var settings = new AdbToolSettings { SdkRoot = androidSdkRoot };
if (!string.IsNullOrEmpty(DEVICE_UDID))
{
settings.Serial = DEVICE_UDID;
}
// Ensure adbkey and adbkey.pub are in place in CI builds
if (IsCIBuild())
{
Information("Ensuring ADB keys are correctly configured for CI environment...");
try
{
var adbKeyPath = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".android");
var adbKeyFile = System.IO.Path.Combine(adbKeyPath, "adbkey");
var adbKeyPubFile = System.IO.Path.Combine(adbKeyPath, "adbkey.pub");
// Deletes existing adbkey and adbkey.pub files in the ~/.android directory to ensure no stale keys remain
if (System.IO.File.Exists(adbKeyFile)) System.IO.File.Delete(adbKeyFile);
if (System.IO.File.Exists(adbKeyPubFile)) System.IO.File.Delete(adbKeyPubFile);
// Regenerates ADB keys using AdbKillServer and AdbStartServer
Information("Regenerating ADB keys...");
AdbKillServer(settings);
AdbStartServer(settings);
Information("ADB keys have been successfully regenerated.");
}
catch (Exception ex)
{
Warning($"Error ensuring ADB keys: {ex.Message}");
}
}
if (waitForBoot)
{
Information("Waiting for the emulator to finish booting...");
// wait for it to finish booting
var waited = 0;
var total = EmulatorBootTimeoutSeconds;
while (AdbShell("getprop sys.boot_completed", settings).FirstOrDefault() != "1")
{
System.Threading.Thread.Sleep(1000);
Information("Waiting {0}/{1} seconds for the emulator to boot up.", waited, total);
if (waited++ > total)
{
throw new Exception("The emulator did not finish booting in time.");
}
// something may be wrong with ADB, so restart every 30 seconds just in case
if (waited % 30 == 0 && IsCIBuild())
{
Information("Trying to restart ADB just in case...");
AdbKillServer(adbSettings);
}
}
Information("Waited {0} seconds for the emulator to boot up.", waited);
}
if (IsCIBuild())
{
Information("Setting Logcat properties...");
AdbLogcat(new AdbLogcatOptions() { Clear = true });
AdbShell("logcat -G 16M", settings);
Information("Finished setting Logcat properties.");
}
Information("Setting the ADB properties...");
var lines = AdbShell("setprop debug.mono.log default,mono_log_level=debug,mono_log_mask=all", settings);
Information("{0}", string.Join("\n", lines));
lines = AdbShell("getprop debug.mono.log", settings);
Information("{0}", string.Join("\n", lines));
Information("Finished setting ADB properties.");
}