Permalink
Browse files

[tests] Update emulator to the latest version, switch to API 28 (#2119)

Updates the Android emulator to the latest version available,
currently `4969155` a.k.a. v27.3.10, and:

  * Switch its system image to API-28, and
  * Make sure that the emulator is started from the `emulator` subdir
    of the Android SDK root (the binary in `tools` won't work anymore),
  * Attempt to not error out when we uninstall packages that don't
    exist in the AVD.

In addition to those changes, two new properties were added to the
`<CreateAndroidEmulator/>` task:

  * `DataPartitionSizeMB` (defaults to `2048`):
     Sets the emulator's data partition size. The data partition
     created by default has only around 800MB of space available,
     which may not be enough to install and run all our tests.
  * `RamSizeMB` (defaults to `2048`): 
     Sets the emulator's RAM size
  • Loading branch information...
grendello authored and jonpryor committed Aug 30, 2018
1 parent 7574c11 commit 7c51a916dd24bf6c5bf3a4a8a83e8d92b2b26b1e
View
@@ -116,7 +116,7 @@
<AndroidToolPath Condition=" '$(AndroidToolPath)' == '' ">$(AndroidSdkFullPath)\tools</AndroidToolPath>
<AndroidToolsBinPath Condition=" '$(AndroidToolsBinPath)' == '' ">$(AndroidToolPath)\bin</AndroidToolsBinPath>
<AndroidToolExe Condition=" '$(AndroidToolExe)' == '' ">android</AndroidToolExe>
<EmulatorToolPath Condition=" '$(EmulatorToolPath)' == '' ">$(AndroidSdkFullPath)\tools</EmulatorToolPath>
<EmulatorToolPath Condition=" '$(EmulatorToolPath)' == '' ">$(AndroidSdkFullPath)\emulator</EmulatorToolPath>
<EmulatorToolExe Condition=" '$(EmulatorToolExe)' == '' ">emulator</EmulatorToolExe>
<NdkBuildPath Condition=" '$(NdkBuildPath)' == '' And '$(HostOS)' != 'Windows' ">$(AndroidNdkDirectory)\ndk-build</NdkBuildPath>
<NdkBuildPath Condition=" '$(NdkBuildPath)' == '' And '$(HostOS)' == 'Windows' ">$(AndroidNdkDirectory)\ndk-build.cmd</NdkBuildPath>
@@ -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);
}
}
@@ -22,7 +22,11 @@ public class CreateAndroidEmulator : Task
public string TargetId {get; set;}
public string ImageName {get; set;} = "XamarinAndroidTestRunner";
public string ImageName {get; set;} = "XamarinAndroidTestRunner";
public string DataPartitionSizeMB {get; set;} = "2048";
public string RamSizeMB {get; set;} = "2048";
public override bool Execute ()
{
@@ -68,6 +72,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;
@@ -23,7 +23,7 @@
<HostOS>Linux</HostOS>
<DestDir>tools</DestDir>
</AndroidSdkItem>
<AndroidSdkItem Include="emulator-linux-4266726">
<AndroidSdkItem Include="emulator-linux-4969155">
<HostOS>Linux</HostOS>
<DestDir>emulator</DestDir>
</AndroidSdkItem>
@@ -42,7 +42,7 @@
<HostOS>Darwin</HostOS>
<DestDir>tools</DestDir>
</AndroidSdkItem>
<AndroidSdkItem Include="emulator-darwin-4266726">
<AndroidSdkItem Include="emulator-darwin-4969155">
<HostOS>Darwin</HostOS>
<DestDir>emulator</DestDir>
</AndroidSdkItem>
@@ -61,7 +61,7 @@
<HostOS>Windows</HostOS>
<DestDir>tools</DestDir>
</AndroidSdkItem>
<AndroidSdkItem Include="emulator-windows-4266726">
<AndroidSdkItem Include="emulator-windows-4969155">
<HostOS>Windows</HostOS>
<DestDir>emulator</DestDir>
</AndroidSdkItem>
@@ -151,10 +151,10 @@
<HostOS></HostOS>
<DestDir>extras\android\m2repository</DestDir>
</AndroidSdkItem>
<AndroidSdkItem Include="x86-21_r05">
<AndroidSdkItem Include="x86-28_r04">
<HostOS></HostOS>
<RelUrl>sys-img/android/</RelUrl>
<DestDir>system-images\android-21\default\x86</DestDir>
<DestDir>system-images\android-28\default\x86</DestDir>
</AndroidSdkItem>
</ItemGroup>
<ItemGroup>
@@ -32,10 +32,12 @@
AndroidAbi="x86"
AndroidSdkHome="$(AndroidSdkDirectory)"
JavaSdkHome="$(JavaSdkDirectory)"
SdkVersion="21"
SdkVersion="28"
ImageName="$(_TestImageName)"
ToolExe="$(AvdManagerToolExe)"
ToolPath="$(AndroidToolsBinPath)"
RamSizeMB="2048"
DataPartitionSizeMB="2048"
/>
<StartAndroidEmulator
Condition=" '$(_ValidAdbTarget)' != 'True' "

0 comments on commit 7c51a91

Please sign in to comment.