Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make fast deployment work with aab files #8990

Merged
merged 6 commits into from
Jun 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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