Skip to content

Commit 6cb5685

Browse files
committed
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.
1 parent 7574c11 commit 6cb5685

5 files changed

Lines changed: 37 additions & 9 deletions

File tree

Configuration.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@
116116
<AndroidToolPath Condition=" '$(AndroidToolPath)' == '' ">$(AndroidSdkFullPath)\tools</AndroidToolPath>
117117
<AndroidToolsBinPath Condition=" '$(AndroidToolsBinPath)' == '' ">$(AndroidToolPath)\bin</AndroidToolsBinPath>
118118
<AndroidToolExe Condition=" '$(AndroidToolExe)' == '' ">android</AndroidToolExe>
119-
<EmulatorToolPath Condition=" '$(EmulatorToolPath)' == '' ">$(AndroidSdkFullPath)\tools</EmulatorToolPath>
119+
<EmulatorToolPath Condition=" '$(EmulatorToolPath)' == '' ">$(AndroidSdkFullPath)\emulator</EmulatorToolPath>
120120
<EmulatorToolExe Condition=" '$(EmulatorToolExe)' == '' ">emulator</EmulatorToolExe>
121121
<NdkBuildPath Condition=" '$(NdkBuildPath)' == '' And '$(HostOS)' != 'Windows' ">$(AndroidNdkDirectory)\ndk-build</NdkBuildPath>
122122
<NdkBuildPath Condition=" '$(NdkBuildPath)' == '' And '$(HostOS)' == 'Windows' ">$(AndroidNdkDirectory)\ndk-build.cmd</NdkBuildPath>

build-tools/Xamarin.Android.Tools.BootstrapTasks/Xamarin.Android.Tools.BootstrapTasks/Adb.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ protected override string GenerateCommandLineCommands ()
5959

6060
protected override void LogEventsFromTextOutput (string singleLine, MessageImportance messageImportance)
6161
{
62-
base.LogEventsFromTextOutput (singleLine, messageImportance);
62+
Log.LogMessage (MessageImportance.Low, singleLine);
6363
Lines.Add (singleLine);
6464
}
6565
}

build-tools/Xamarin.Android.Tools.BootstrapTasks/Xamarin.Android.Tools.BootstrapTasks/CreateAndroidEmulator.cs

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,10 @@ public class CreateAndroidEmulator : Task
2222

2323
public string TargetId {get; set;}
2424

25-
public string ImageName {get; set;} = "XamarinAndroidTestRunner";
25+
public string ImageName {get; set;} = "XamarinAndroidTestRunner";
26+
public string RamSizeMB {get; set;} = "2048";
27+
public string DataPartitionSizeMB { get; set;} = "2048";
28+
2629

2730
public override bool Execute ()
2831
{
@@ -68,6 +71,29 @@ void Run (string android)
6871

6972
var arguments = $"create avd --abi {AndroidAbi} -f -n {ImageName} --package \"{TargetId}\"";
7073
Exec (android, arguments);
74+
75+
string configPath = Path.Combine (Environment.GetFolderPath (Environment.SpecialFolder.Personal), ".android", "avd", $"{ImageName}.avd", "config.ini");
76+
if (!File.Exists (configPath)) {
77+
Log.LogWarning ($"Config file for AVD '{ImageName}' not found at {configPath}");
78+
Log.LogWarning ($"AVD '{ImageName}' will use default emulator settings (memory and data partition size)");
79+
return;
80+
}
81+
82+
ulong diskSize;
83+
if (!UInt64.TryParse (DataPartitionSizeMB, out diskSize))
84+
Log.LogError ($"Invalid data partition size '{DataPartitionSizeMB}' - must be a positive integer value expressing size in megabytes");
85+
86+
ulong ramSize;
87+
if (!UInt64.TryParse (RamSizeMB, out ramSize))
88+
Log.LogError ($"Invalid RAM size '{RamSizeMB}' - must be a positive integer value expressing size in megabytes");
89+
90+
if (Log.HasLoggedErrors)
91+
return;
92+
93+
File.AppendAllLines (configPath, new string[] {
94+
$"disk.dataPartition.size={diskSize}M",
95+
$"hw.ramSize={ramSize}"
96+
});
7197
}
7298

7399
StreamWriter stdin;

build-tools/android-toolchain/android-toolchain.projitems

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
<HostOS>Linux</HostOS>
2424
<DestDir>tools</DestDir>
2525
</AndroidSdkItem>
26-
<AndroidSdkItem Include="emulator-linux-4266726">
26+
<AndroidSdkItem Include="emulator-linux-4969155">
2727
<HostOS>Linux</HostOS>
2828
<DestDir>emulator</DestDir>
2929
</AndroidSdkItem>
@@ -42,7 +42,7 @@
4242
<HostOS>Darwin</HostOS>
4343
<DestDir>tools</DestDir>
4444
</AndroidSdkItem>
45-
<AndroidSdkItem Include="emulator-darwin-4266726">
45+
<AndroidSdkItem Include="emulator-darwin-4969155">
4646
<HostOS>Darwin</HostOS>
4747
<DestDir>emulator</DestDir>
4848
</AndroidSdkItem>
@@ -61,7 +61,7 @@
6161
<HostOS>Windows</HostOS>
6262
<DestDir>tools</DestDir>
6363
</AndroidSdkItem>
64-
<AndroidSdkItem Include="emulator-windows-4266726">
64+
<AndroidSdkItem Include="emulator-windows-4969155">
6565
<HostOS>Windows</HostOS>
6666
<DestDir>emulator</DestDir>
6767
</AndroidSdkItem>
@@ -151,10 +151,10 @@
151151
<HostOS></HostOS>
152152
<DestDir>extras\android\m2repository</DestDir>
153153
</AndroidSdkItem>
154-
<AndroidSdkItem Include="x86-21_r05">
154+
<AndroidSdkItem Include="x86-28_r04">
155155
<HostOS></HostOS>
156156
<RelUrl>sys-img/android/</RelUrl>
157-
<DestDir>system-images\android-21\default\x86</DestDir>
157+
<DestDir>system-images\android-28\default\x86</DestDir>
158158
</AndroidSdkItem>
159159
</ItemGroup>
160160
<ItemGroup>

build-tools/scripts/TestApks.targets

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,12 @@
3232
AndroidAbi="x86"
3333
AndroidSdkHome="$(AndroidSdkDirectory)"
3434
JavaSdkHome="$(JavaSdkDirectory)"
35-
SdkVersion="21"
35+
SdkVersion="28"
3636
ImageName="$(_TestImageName)"
3737
ToolExe="$(AvdManagerToolExe)"
3838
ToolPath="$(AndroidToolsBinPath)"
39+
RamSizeMB="2048"
40+
DataPartitionSizeMB="2048"
3941
/>
4042
<StartAndroidEmulator
4143
Condition=" '$(_ValidAdbTarget)' != 'True' "

0 commit comments

Comments
 (0)