Skip to content

Commit

Permalink
Merge branch 'main' into dev/grendel/perfetto-integration
Browse files Browse the repository at this point in the history
* main:
  [Xamarin.Android.Build.Tasks] fix detection of "Android libraries" (#8904)
  [Mono.Android] fix potential leak of RunnableImplementors (#8900)
  • Loading branch information
grendello committed Apr 26, 2024
2 parents 7d0165e + 8e1871b commit d1c22e8
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -269,11 +269,7 @@ public void ProjectDependencies ([Values(true, false)] bool projectReference)
};
libB.Sources.Clear ();
libB.Sources.Add (new BuildItem.Source ("Foo.cs") {
TextContent = () => @"public class Foo {
public Foo () {
var bar = new Bar();
}
}",
TextContent = () => "public class Foo : Bar { }",
});

var libC = new XamarinAndroidLibraryProject () {
Expand All @@ -283,7 +279,7 @@ public Foo () {
};
libC.Sources.Clear ();
libC.Sources.Add (new BuildItem.Source ("Bar.cs") {
TextContent = () => "public class Bar { }",
TextContent = () => "public class Bar : Java.Lang.Object { }",
});
libC.Sources.Add (new BuildItem ("EmbeddedResource", "Foo.resx") {
TextContent = () => InlineData.ResxWithContents ("<data name=\"CancelButton\"><value>Cancel</value></data>")
Expand All @@ -309,8 +305,8 @@ public Foo () {
ProjectName = "AppA",
IsRelease = true,
Sources = {
new BuildItem.Source ("Bar.cs") {
TextContent = () => "public class Bar : Foo { }",
new BuildItem.Source ("Baz.cs") {
TextContent = () => "public class Baz : Foo { }",
},
new BuildItem ("EmbeddedResource", "Foo.resx") {
TextContent = () => InlineData.ResxWithContents ("<data name=\"CancelButton\"><value>Cancel</value></data>")
Expand All @@ -321,6 +317,10 @@ public Foo () {
}
};
appA.AddReference (libB);
if (!projectReference) {
// @(ProjectReference) implicits adds this reference. For `class Baz : Foo : Bar`:
appA.OtherBuildItems.Add (new BuildItem.Reference ($@"..\{libC.ProjectName}\bin\Release\{libC.TargetFramework}\{libC.ProjectName}.dll"));
}
var appBuilder = CreateApkBuilder (Path.Combine (path, appA.ProjectName));
Assert.IsTrue (appBuilder.Build (appA), $"{appA.ProjectName} should succeed");

Expand All @@ -332,6 +332,17 @@ public Foo () {
helper.AssertContainsEntry ($"assemblies/{libC.ProjectName}.dll");
helper.AssertContainsEntry ($"assemblies/es/{appA.ProjectName}.resources.dll");
helper.AssertContainsEntry ($"assemblies/es/{libC.ProjectName}.resources.dll");

var intermediate = Path.Combine (Root, appBuilder.ProjectDirectory, appA.IntermediateOutputPath);
var dexFile = Path.Combine (intermediate, "android", "bin", "classes.dex");
FileAssert.Exists (dexFile);

// NOTE: the crc hashes here might change one day, but if we used [Android.Runtime.Register("")]
// LibraryB.dll would have a reference to Mono.Android.dll, which invalidates the test.
string className = "Lcrc6414a4b78410c343a2/Bar;";
Assert.IsTrue (DexUtils.ContainsClass (className, dexFile, AndroidSdkPath), $"`{dexFile}` should include `{className}`!");
className = "Lcrc646d2d82b4d8b39bd8/Foo;";
Assert.IsTrue (DexUtils.ContainsClass (className, dexFile, AndroidSdkPath), $"`{dexFile}` should include `{className}`!");
}

[Test]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -277,8 +277,13 @@ public static void LogWarning (object log, string msg, params object [] args)
#if MSBUILD
public static bool IsMonoAndroidAssembly (ITaskItem assembly)
{
// NOTE: look for both MonoAndroid and Android
var tfi = assembly.GetMetadata ("TargetFrameworkIdentifier");
if (string.Compare (tfi, "MonoAndroid", StringComparison.OrdinalIgnoreCase) == 0)
if (tfi.IndexOf ("Android", StringComparison.OrdinalIgnoreCase) != -1)
return true;

var tpi = assembly.GetMetadata ("TargetPlatformIdentifier");
if (tpi.IndexOf ("Android", StringComparison.OrdinalIgnoreCase) != -1)
return true;

var hasReference = assembly.GetMetadata ("HasMonoAndroidReference");
Expand Down

0 comments on commit d1c22e8

Please sign in to comment.