Skip to content

Commit 4540aa4

Browse files
committed
[Xamarin.Android.Build.Tasks] Fix an issue where library projects cannot be debugged.
The linker was not producing ppdb files. What is supposed to happen is the linker if it changes a dll should emit a new pdb file along with it. Because none of the assemblies were being loaded with debug symbols. Hence no updated pdb. So this commit enables the reading of Symbols as part of the linker process to ensure that we are able to emit the new pdb when required.
1 parent 89828ed commit 4540aa4

File tree

2 files changed

+66
-1
lines changed

2 files changed

+66
-1
lines changed

src/Xamarin.Android.Build.Tasks/Tasks/LinkAssemblies.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,9 @@ public override bool Execute ()
8484

8585
var rp = new ReaderParameters {
8686
InMemory = true,
87+
ReadSymbols = true,
8788
};
88-
using (var res = new DirectoryAssemblyResolver (Log.LogWarning, loadDebugSymbols: false, loadReaderParameters: rp)) {
89+
using (var res = new DirectoryAssemblyResolver (Log.LogWarning, loadDebugSymbols: true, loadReaderParameters: rp)) {
8990
return Execute (res);
9091
}
9192
}

src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/BuildTest.cs

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -499,6 +499,70 @@ public void BuildBasicApplicationCheckMdbRepeatBuild ()
499499
}
500500
}
501501

502+
[Test]
503+
public void BuildAppCheckDebugSymbols ()
504+
{
505+
var path = Path.Combine ("temp", TestContext.CurrentContext.Test.Name);
506+
var lib = new XamarinAndroidLibraryProject () {
507+
IsRelease = false,
508+
ProjectName = "Library1",
509+
Sources = {
510+
new BuildItem.Source ("Class1.cs") {
511+
TextContent = () => @"using System;
512+
namespace Library1 {
513+
public class Class1 : Java.Lang.Object, global::Android.Views.View.IOnClickListener {
514+
void global::Android.Views.View.IOnClickListener.OnClick(global::Android.Views.View v)
515+
{
516+
}
517+
}
518+
}
519+
",
520+
},
521+
},
522+
};
523+
var proj = new XamarinAndroidApplicationProject () {
524+
IsRelease = false,
525+
ProjectName = "App1",
526+
References = { new BuildItem ("ProjectReference", "..\\Library1\\Library1.csproj") },
527+
Sources = {
528+
new BuildItem.Source ("Class2.cs") {
529+
TextContent= () => @"
530+
using System;
531+
namespace App1
532+
{
533+
public class Class2
534+
{
535+
Library1.Class1 c;
536+
public Class2 ()
537+
{
538+
}
539+
}
540+
}"
541+
},
542+
},
543+
};
544+
proj.SetProperty (KnownProperties.AndroidLinkMode, AndroidLinkMode.None.ToString ());
545+
using (var libb = CreateDllBuilder (Path.Combine (path, "Library1"))) {
546+
Assert.IsTrue (libb.Build (lib), "Library1 Build should have succeeded.");
547+
using (var b = CreateApkBuilder (Path.Combine (path, "App1"))) {
548+
Assert.IsTrue (b.Build (proj), "App1 Build should have succeeded.");
549+
var assetsPdb = Path.Combine (Root, b.ProjectDirectory, proj.IntermediateOutputPath, "android", "assets", "Library1.pdb");
550+
var linkDst = Path.Combine (Root, b.ProjectDirectory, proj.IntermediateOutputPath, "linkdst", "Library1.pdb");
551+
var linkSrc = Path.Combine (Root, b.ProjectDirectory, proj.IntermediateOutputPath, "linksrc", "Library1.pdb");
552+
Assert.IsTrue (
553+
File.Exists (assetsPdb),
554+
"Library1.pdb must be copied to Intermediate directory");
555+
Assert.IsTrue (
556+
File.Exists (linkDst),
557+
"Library1.pdb must be copied to linkdst directory");
558+
Assert.IsTrue (
559+
File.Exists (linkSrc),
560+
"Library1.pdb must be copied to linksrc directory");
561+
FileAssert.AreEqual (linkDst, assetsPdb, $"Library1.pdb in {assetsPdb} should match {linkDst}");
562+
}
563+
}
564+
}
565+
502566
[Test]
503567
public void BuildBasicApplicationCheckMdbAndPortablePdb ()
504568
{

0 commit comments

Comments
 (0)