diff --git a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/BuildTest.cs b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/BuildTest.cs index 952c5c9d374..b17f7beafbb 100644 --- a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/BuildTest.cs +++ b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/BuildTest.cs @@ -2560,5 +2560,22 @@ public void CheckLintResourceFileReferencesAreFixed () StringAssertEx.DoesNotContain (errorFilePath, b.LastBuildOutput, $"Path {errorFilePath} should have been replaced."); } } + + [Test] + public void SimilarAndroidXAssemblyNames ([Values(true, false)] bool publishTrimmed) + { + var proj = new XamarinAndroidApplicationProject { + IsRelease = true, + AotAssemblies = publishTrimmed, + PackageReferences = { + new Package { Id = "Xamarin.AndroidX.CustomView", Version = "1.1.0.17" }, + new Package { Id = "Xamarin.AndroidX.CustomView.PoolingContainer", Version = "1.0.0.4" }, + } + }; + proj.SetProperty (KnownProperties.PublishTrimmed, publishTrimmed.ToString()); + proj.MainActivity = proj.DefaultMainActivity.Replace ("//${AFTER_ONCREATE}", "AndroidX.CustomView.PoolingContainer.PoolingContainer.IsPoolingContainer (null);"); + using var builder = CreateApkBuilder (); + Assert.IsTrue (builder.Build (proj), "Build should have succeeded."); + } } } diff --git a/src/Xamarin.Android.Build.Tasks/Utilities/MarshalMethodsAssemblyRewriter.cs b/src/Xamarin.Android.Build.Tasks/Utilities/MarshalMethodsAssemblyRewriter.cs index acd69f2d7ea..4131349d150 100644 --- a/src/Xamarin.Android.Build.Tasks/Utilities/MarshalMethodsAssemblyRewriter.cs +++ b/src/Xamarin.Android.Build.Tasks/Utilities/MarshalMethodsAssemblyRewriter.cs @@ -118,11 +118,12 @@ public void Rewrite (DirectoryAssemblyResolver resolver, List targetAsse foreach (AssemblyDefinition asm in uniqueAssemblies) { foreach (string path in GetAssemblyPaths (asm)) { var writerParams = new WriterParameters { - WriteSymbols = (File.Exists (path + ".mdb") || File.Exists (Path.ChangeExtension (path, ".pdb"))), + WriteSymbols = File.Exists (Path.ChangeExtension (path, ".pdb")), }; - - string output = $"{path}.new"; + string directory = Path.Combine (Path.GetDirectoryName (path), "new"); + Directory.CreateDirectory (directory); + string output = Path.Combine (directory, Path.GetFileName (path)); log.LogDebugMessage ($"Writing new version of assembly: {output}"); // TODO: this should be used eventually, but it requires that all the types are reloaded from the assemblies before typemaps are generated @@ -137,36 +138,23 @@ public void Rewrite (DirectoryAssemblyResolver resolver, List targetAsse // versions around. foreach (string path in newAssemblyPaths) { string? pdb = null; - string? mdb = null; - string source = Path.ChangeExtension (Path.Combine (Path.GetDirectoryName (path), Path.GetFileNameWithoutExtension (path)), ".pdb"); + string source = Path.ChangeExtension (path, ".pdb"); if (File.Exists (source)) { pdb = source; } - source = $"{path}.mdb"; - if (File.Exists (source)) { - mdb = source; - } - foreach (string targetPath in targetAssemblyPaths) { - string target = Path.Combine (targetPath, Path.GetFileNameWithoutExtension (path)); + string target = Path.Combine (targetPath, Path.GetFileName (path)); CopyFile (path, target); if (!String.IsNullOrEmpty (pdb)) { - target = Path.ChangeExtension (Path.Combine (targetPath, Path.GetFileNameWithoutExtension (pdb)), ".pdb"); - CopyFile (pdb, target); - } - - if (!String.IsNullOrEmpty (mdb)) { - target = Path.Combine (targetPath, Path.ChangeExtension (Path.GetFileName (path), ".mdb")); - CopyFile (mdb, target); + CopyFile (pdb, Path.ChangeExtension (target, ".pdb")); } } RemoveFile (path); RemoveFile (pdb); - RemoveFile (mdb); } void CopyFile (string source, string target) @@ -182,6 +170,7 @@ void RemoveFile (string? path) } try { + log.LogDebugMessage ($"Deleting: {path}"); File.Delete (path); } catch (Exception ex) { log.LogWarning ($"Unable to delete source file '{path}'");