From 6cb5685b23addca8b93424ccbb097390f53b9d1c Mon Sep 17 00:00:00 2001 From: Marek Habersack Date: Wed, 29 Aug 2018 21:12:58 +0200 Subject: [PATCH 1/2] Update emulator to the latest version, switch to API 28 This commit updates the Android emulator to the latest version available (`4969155` a.k.a. v27.3.10), switches its system image to API 28, makes sure that the emulator is started from the `emulator` subdir of the Android SDK root (the binary in `tools` won't work anymore) and makes sure we don't error out when we attempt to uninstall packages that don't exist in the AVD. In addition to those changes, two new properties were added to the `CreateAndroidEmulator` task: * `RamSizeMB` (defaults to `2048`) Allows to set the emulator's RAM size * `DataPartitionSizeMB` (defaults to `2048`) Allows to set the emulator's data partition size. The data partition cretaed by default has only around 800MB of space available which may not be enough to install and run all our tests. --- Configuration.props | 2 +- .../Adb.cs | 2 +- .../CreateAndroidEmulator.cs | 28 ++++++++++++++++++- .../android-toolchain.projitems | 10 +++---- build-tools/scripts/TestApks.targets | 4 ++- 5 files changed, 37 insertions(+), 9 deletions(-) diff --git a/Configuration.props b/Configuration.props index b1c3d747f36..c6dfe92a4ed 100644 --- a/Configuration.props +++ b/Configuration.props @@ -116,7 +116,7 @@ $(AndroidSdkFullPath)\tools $(AndroidToolPath)\bin android - $(AndroidSdkFullPath)\tools + $(AndroidSdkFullPath)\emulator emulator $(AndroidNdkDirectory)\ndk-build $(AndroidNdkDirectory)\ndk-build.cmd diff --git a/build-tools/Xamarin.Android.Tools.BootstrapTasks/Xamarin.Android.Tools.BootstrapTasks/Adb.cs b/build-tools/Xamarin.Android.Tools.BootstrapTasks/Xamarin.Android.Tools.BootstrapTasks/Adb.cs index 5dd87e5f507..ced5311531d 100644 --- a/build-tools/Xamarin.Android.Tools.BootstrapTasks/Xamarin.Android.Tools.BootstrapTasks/Adb.cs +++ b/build-tools/Xamarin.Android.Tools.BootstrapTasks/Xamarin.Android.Tools.BootstrapTasks/Adb.cs @@ -59,7 +59,7 @@ protected override string GenerateCommandLineCommands () protected override void LogEventsFromTextOutput (string singleLine, MessageImportance messageImportance) { - base.LogEventsFromTextOutput (singleLine, messageImportance); + Log.LogMessage (MessageImportance.Low, singleLine); Lines.Add (singleLine); } } diff --git a/build-tools/Xamarin.Android.Tools.BootstrapTasks/Xamarin.Android.Tools.BootstrapTasks/CreateAndroidEmulator.cs b/build-tools/Xamarin.Android.Tools.BootstrapTasks/Xamarin.Android.Tools.BootstrapTasks/CreateAndroidEmulator.cs index c332f2b9cfd..2a4cebfdfc9 100644 --- a/build-tools/Xamarin.Android.Tools.BootstrapTasks/Xamarin.Android.Tools.BootstrapTasks/CreateAndroidEmulator.cs +++ b/build-tools/Xamarin.Android.Tools.BootstrapTasks/Xamarin.Android.Tools.BootstrapTasks/CreateAndroidEmulator.cs @@ -22,7 +22,10 @@ public class CreateAndroidEmulator : Task public string TargetId {get; set;} - public string ImageName {get; set;} = "XamarinAndroidTestRunner"; + public string ImageName {get; set;} = "XamarinAndroidTestRunner"; + public string RamSizeMB {get; set;} = "2048"; + public string DataPartitionSizeMB { get; set;} = "2048"; + public override bool Execute () { @@ -68,6 +71,29 @@ void Run (string android) var arguments = $"create avd --abi {AndroidAbi} -f -n {ImageName} --package \"{TargetId}\""; Exec (android, arguments); + + string configPath = Path.Combine (Environment.GetFolderPath (Environment.SpecialFolder.Personal), ".android", "avd", $"{ImageName}.avd", "config.ini"); + if (!File.Exists (configPath)) { + Log.LogWarning ($"Config file for AVD '{ImageName}' not found at {configPath}"); + Log.LogWarning ($"AVD '{ImageName}' will use default emulator settings (memory and data partition size)"); + return; + } + + ulong diskSize; + if (!UInt64.TryParse (DataPartitionSizeMB, out diskSize)) + Log.LogError ($"Invalid data partition size '{DataPartitionSizeMB}' - must be a positive integer value expressing size in megabytes"); + + ulong ramSize; + if (!UInt64.TryParse (RamSizeMB, out ramSize)) + Log.LogError ($"Invalid RAM size '{RamSizeMB}' - must be a positive integer value expressing size in megabytes"); + + if (Log.HasLoggedErrors) + return; + + File.AppendAllLines (configPath, new string[] { + $"disk.dataPartition.size={diskSize}M", + $"hw.ramSize={ramSize}" + }); } StreamWriter stdin; diff --git a/build-tools/android-toolchain/android-toolchain.projitems b/build-tools/android-toolchain/android-toolchain.projitems index 8c9e9934e24..dd2a478e801 100644 --- a/build-tools/android-toolchain/android-toolchain.projitems +++ b/build-tools/android-toolchain/android-toolchain.projitems @@ -23,7 +23,7 @@ Linux tools - + Linux emulator @@ -42,7 +42,7 @@ Darwin tools - + Darwin emulator @@ -61,7 +61,7 @@ Windows tools - + Windows emulator @@ -151,10 +151,10 @@ extras\android\m2repository - + sys-img/android/ - system-images\android-21\default\x86 + system-images\android-28\default\x86 diff --git a/build-tools/scripts/TestApks.targets b/build-tools/scripts/TestApks.targets index 906c2c6b4a8..566742f7237 100644 --- a/build-tools/scripts/TestApks.targets +++ b/build-tools/scripts/TestApks.targets @@ -32,10 +32,12 @@ AndroidAbi="x86" AndroidSdkHome="$(AndroidSdkDirectory)" JavaSdkHome="$(JavaSdkDirectory)" - SdkVersion="21" + SdkVersion="28" ImageName="$(_TestImageName)" ToolExe="$(AvdManagerToolExe)" ToolPath="$(AndroidToolsBinPath)" + RamSizeMB="2048" + DataPartitionSizeMB="2048" /> Date: Thu, 30 Aug 2018 15:07:40 -0400 Subject: [PATCH 2/2] A foolish consistency is the hobgoblin of little minds But is it actually foolish? --- .../CreateAndroidEmulator.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/build-tools/Xamarin.Android.Tools.BootstrapTasks/Xamarin.Android.Tools.BootstrapTasks/CreateAndroidEmulator.cs b/build-tools/Xamarin.Android.Tools.BootstrapTasks/Xamarin.Android.Tools.BootstrapTasks/CreateAndroidEmulator.cs index 2a4cebfdfc9..24dbdbb21f0 100644 --- a/build-tools/Xamarin.Android.Tools.BootstrapTasks/Xamarin.Android.Tools.BootstrapTasks/CreateAndroidEmulator.cs +++ b/build-tools/Xamarin.Android.Tools.BootstrapTasks/Xamarin.Android.Tools.BootstrapTasks/CreateAndroidEmulator.cs @@ -23,8 +23,9 @@ public class CreateAndroidEmulator : Task public string TargetId {get; set;} public string ImageName {get; set;} = "XamarinAndroidTestRunner"; + + public string DataPartitionSizeMB {get; set;} = "2048"; public string RamSizeMB {get; set;} = "2048"; - public string DataPartitionSizeMB { get; set;} = "2048"; public override bool Execute ()