Skip to content

Commit

Permalink
[Xamarin.Android.Build.Tasks] fastdev works with aab files (#8990)
Browse files Browse the repository at this point in the history
Context: xamarin/monodroid@c6aae9e

Changes: xamarin/monodroid@93ab95e...c6aae9e

  * xamarin/monodroid@c6aae9e5a: [tools/msbuild] Allow aab to use Fast Deployment. (xamarin/monodroid#1201)
  * xamarin/monodroid@1f7b83f50: Bump to xamarin/xamarin-android/main@f5fcd4d (xamarin/monodroid#1492)
  * xamarin/monodroid@4cda6063b: Bump to xamarin/androidtools@63b52d2 (xamarin/monodroid#1487)
  * xamarin/monodroid@2712c4863: Bump to xamarin/android-sdk-installer@0b8f403 (xamarin/monodroid#1489)
  * xamarin/monodroid@2a85ae88f: Bump to xamarin/xamarin-android/main@935808b (xamarin/monodroid#1491)
  * xamarin/monodroid@92b297ca1: Bump to xamarin/xamarin-android/main@c6117431 (xamarin/monodroid#1490)
  * xamarin/monodroid@7fe876775: Force loc task pool image to windows (xamarin/monodroid#1486)

Commit xamarin/monodroid@c6aae9e5a removed the restriction from using
`.aab` files during fast deployment.   While using an `.aab` will
still be slower that using an `.apk`, it should still speed up the
development process for those using things like asset packs.

The reason it is slower is because the `.aab` file has to go through
`bundle-tool` to be packaged and installed.  This is a slow process.
The `.apk` is much faster as we work with it directly. 

Numerous unit tests have been updated to test fast deployment when
using `.aab` files.  As a result we have had to increase the number
of CI bots we use so we can spread out the new tests amongst more
machines.
  • Loading branch information
dellis1972 authored Jun 13, 2024
1 parent 553e927 commit 0555f6a
Show file tree
Hide file tree
Showing 9 changed files with 54 additions and 19 deletions.
2 changes: 1 addition & 1 deletion .external
Original file line number Diff line number Diff line change
@@ -1 +1 @@
xamarin/monodroid:main@93ab95e18077d56d9d55ce7b4069a534e2dea35e
xamarin/monodroid:main@c6aae9e5a154cfbf2c3a94e046fa2c747c3b82e2
3 changes: 2 additions & 1 deletion Xamarin.Android.code-workspace
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
}
],
"settings": {
"nxunitExplorer.logpanel": true
"nxunitExplorer.logpanel": true,
"java.compile.nullAnalysis.mode": "disabled"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ parameters:
stageName: msbuilddevice_tests
job_name: 'mac_dotnetdevice_tests'
dependsOn: mac_build
agent_count: 8
agent_count: 12
stageCondition: succeeded()
stagePrefix: ''
xaSourcePath: $(System.DefaultWorkingDirectory)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ stages:
testOS: macOS
jobName: mac_msbuild_tests
jobDisplayName: macOS > Tests > MSBuild
agentCount: 8
agentCount: 14
xaSourcePath: ${{ parameters.xaSourcePath }}
repositoryAlias: ${{ parameters.repositoryAlias }}
commit: ${{ parameters.commit }}
Expand Down
2 changes: 2 additions & 0 deletions src/Xamarin.Android.Build.Tasks/Tasks/ProcessAssemblies.cs
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ static bool IsFromAKnownRuntimePack (ITaskItem assembly)
// Sometimes .pdb files are not included in @(ResolvedFileToPublish), so add them if they exist
if (File.Exists (symbolPath)) {
symbols [symbolPath] = symbol = new TaskItem (symbolPath);
return symbol;
}
}
return symbol;
Expand Down Expand Up @@ -185,6 +186,7 @@ void SetIt (ITaskItem? item)
}

string destination = Path.Combine (abi, item.GetMetadata ("DestinationSubDirectory"));
//Log.LogDebugMessage ($"DEBUG!!!'{item.ItemSpec}' '{rid}' = '{abi}'. DestinationSubDirectory='{destination}'");
item.SetMetadata ("DestinationSubDirectory", destination + Path.DirectorySeparatorChar);
item.SetMetadata ("DestinationSubPath", Path.Combine (destination, Path.GetFileName (item.ItemSpec)));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using System.Xml.Linq;
using System.Xml.XPath;
using Xamarin.ProjectTools;
using System.Runtime.InteropServices;

namespace Xamarin.Android.Build.Tests
{
Expand Down Expand Up @@ -77,7 +78,10 @@ public void DeviceSetup ()
}
SetAdbLogcatBufferSize (128);
CreateGuestUser (GuestUserName);
return;
}
TestContext.Out.WriteLine ($"LOG DeviceSetup: No Device!!!!");
DeviceAbi = RuntimeInformation.OSArchitecture == Architecture.Arm64 ? "arm64-v8a" : "x86_64";
}

[OneTimeTearDown]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -496,10 +496,6 @@ Copyright (C) 2011-2012 Xamarin. All rights reserved.
ResourceName="XA0119_LinkTool"
Condition=" '$(EmbedAssembliesIntoApk)' != 'True' And '$(AndroidLinkTool)' != '' "
/>
<AndroidWarning Code="XA0119"
ResourceName="XA0119_AAB"
Condition=" '$(EmbedAssembliesIntoApk)' != 'True' And '$(AndroidPackageFormat)' == 'aab' "
/>
<AndroidWarning Code="XA0119"
ResourceName="XA0119_Interpreter"
Condition=" '$(AndroidUseInterpreter)' == 'True' And '$(AotAssemblies)' == 'True' "
Expand Down
22 changes: 21 additions & 1 deletion tests/MSBuildDeviceIntegration/Tests/DebuggingTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,11 @@ public void ClassLibraryMainLauncherRuns ([Values (true, false)] bool preloadAss
/* activityStarts */ true,
/* packageFormat */ "aab",
},
new object[] {
/* embedAssemblies */ false,
/* activityStarts */ true,
/* packageFormat */ "aab",
},
};
#pragma warning restore 414

Expand Down Expand Up @@ -325,13 +330,27 @@ public override void OnCreate ()
/* packageFormat */ "aab",
/* useLatestSdk */ true,
},
new object[] {
/* embedAssemblies */ false,
/* allowDeltaInstall */ false,
/* user */ null,
/* packageFormat */ "aab",
/* useLatestSdk */ true,
},
new object[] {
/* embedAssemblies */ true,
/* allowDeltaInstall */ false,
/* user */ DeviceTest.GuestUserName,
/* packageFormat */ "aab",
/* useLatestSdk */ true,
},
new object[] {
/* embedAssemblies */ false,
/* allowDeltaInstall */ false,
/* user */ DeviceTest.GuestUserName,
/* packageFormat */ "aab",
/* useLatestSdk */ true,
},
};
#pragma warning restore 414

Expand Down Expand Up @@ -388,7 +407,8 @@ public Foo ()
app.SetProperty ("AndroidPackageFormat", packageFormat);
app.MainPage = app.MainPage.Replace ("InitializeComponent ();", "InitializeComponent (); new Foo ();");
app.AddReference (lib);
app.SetAndroidSupportedAbis (DeviceAbi);
var abis = new [] { DeviceAbi };
app.SetRuntimeIdentifiers (abis);
app.SetProperty (KnownProperties._AndroidAllowDeltaInstall, allowDeltaInstall.ToString ());
app.SetDefaultTargetDevice ();
using (var libBuilder = CreateDllBuilder (Path.Combine (path, lib.ProjectName)))
Expand Down
32 changes: 22 additions & 10 deletions tests/MSBuildDeviceIntegration/Tests/InstallTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,9 @@ public void TestAndroidStoreKey (bool useApkSigner, bool isRelease, string packa

// https://xamarin.github.io/bugzilla-archives/31/31705/bug.html
[Test]
public void LocalizedAssemblies_ShouldBeFastDeployed ()
[TestCase ("apk")]
[TestCase ("aab")]
public void LocalizedAssemblies_ShouldBeFastDeployed (string packageFormat)
{
AssertCommercialBuild ();

Expand All @@ -469,6 +471,7 @@ public void LocalizedAssemblies_ShouldBeFastDeployed ()
EmbedAssembliesIntoApk = false,
};
InlineData.AddCultureResourcesToProject (app, "Foo", "CancelButton");
app.SetProperty ("AndroidPackageFormat", packageFormat);
app.References.Add (new BuildItem.ProjectReference ($"..\\{lib.ProjectName}\\{lib.ProjectName}.csproj", lib.ProjectName, lib.ProjectGuid));

using (var libBuilder = CreateDllBuilder (Path.Combine (path, lib.ProjectName)))
Expand All @@ -494,12 +497,14 @@ public void LocalizedAssemblies_ShouldBeFastDeployed ()
}

[Test]
public void IncrementalFastDeployment ()
[TestCase ("apk")]
[TestCase ("aab")]
public void IncrementalFastDeployment (string packageFormat)
{
AssertCommercialBuild ();

var class1src = new BuildItem.Source ("Class1.cs") {
TextContent = () => "namespace Library1 { public class Class1 { public static int foo = 0; } }"
TextContent = () => "namespace Library1 { public class Class1 { public static int foo = 500; } }"
};
var lib1 = new XamarinAndroidLibraryProject () {
ProjectName = "Library1",
Expand All @@ -509,7 +514,7 @@ public void IncrementalFastDeployment ()
};

var class2src = new BuildItem.Source ("Class2.cs") {
TextContent = () => "namespace Library2 { public class Class2 { public static int foo = 0; } }"
TextContent = () => "namespace Library2 { public class Class2 { public static int foo = 40; } }"
};
var lib2 = new DotNetStandard {
ProjectName = "Library2",
Expand All @@ -527,16 +532,21 @@ public void IncrementalFastDeployment ()
new BuildItem ("ProjectReference", "..\\Library2\\Library2.csproj"),
},
};
app.SetProperty ("AndroidPackageFormat", packageFormat);

// Set up library projects
var rootPath = Path.Combine (Root, "temp", TestName);
using (var lb1 = CreateDllBuilder (Path.Combine (rootPath, lib1.ProjectName)))
using (var lb1 = CreateDllBuilder (Path.Combine (rootPath, lib1.ProjectName))) {
lb1.BuildLogFile = "build.log";
Assert.IsTrue (lb1.Build (lib1), "First library build should have succeeded.");
using (var lb2 = CreateDllBuilder (Path.Combine (rootPath, lib2.ProjectName)))
}
using (var lb2 = CreateDllBuilder (Path.Combine (rootPath, lib2.ProjectName))) {
lb2.BuildLogFile = "build.log";
Assert.IsTrue (lb2.Build (lib2), "Second library build should have succeeded.");
}

long lib1FirstBuildSize = new FileInfo (Path.Combine (rootPath, lib1.ProjectName, lib1.OutputPath, "Library1.dll")).Length;

using (var builder = CreateApkBuilder (Path.Combine (rootPath, app.ProjectName))) {
builder.Verbosity = LoggerVerbosity.Detailed;
builder.ThrowOnBuildFailure = false;
Expand All @@ -560,13 +570,15 @@ public void IncrementalFastDeployment ()
File.SetLastWriteTimeUtc (file, DateTime.UtcNow);
}

class1src.TextContent = () => "namespace Library1 { public class Class1 { public static int foo = 100; } }";
class1src.TextContent = () => "namespace Library1 { public class Class1 { public static int foo = 1; } }";
class1src.Timestamp = DateTime.UtcNow.AddSeconds(1);
using (var lb1 = CreateDllBuilder (Path.Combine (rootPath, lib1.ProjectName)))
using (var lb1 = CreateDllBuilder (Path.Combine (rootPath, lib1.ProjectName))) {
lb1.BuildLogFile = "build2.log";
Assert.IsTrue (lb1.Build (lib1), "Second library build should have succeeded.");
}

long lib1SecondBuildSize = new FileInfo (Path.Combine (rootPath, lib1.ProjectName, lib1.OutputPath, "Library1.dll")).Length;
Assert.AreEqual (lib1FirstBuildSize, lib1SecondBuildSize, "Library2.dll was not the same size.");
Assert.AreEqual (lib1FirstBuildSize, lib1SecondBuildSize, "Library1.dll was not the same size.");

builder.BuildLogFile = "install3.log";
Assert.IsTrue (builder.Install (app, doNotCleanupOnUpdate: true, saveProject: false), "Third install should have succeeded.");
Expand Down

0 comments on commit 0555f6a

Please sign in to comment.