0

I'm building an app that searches songs on Genius and gets their lyrics to be shown to users. I want to create another activity that uses a different layout from the main one to show those lyrics, so I created a .cs activity and a .axml layout file called lyrics_viwer.axml (I know there's a typo there).

I found that when I build the solution without including the line SetContentView(Resource.Id.lyrics_viwer) it gives no errors, but including it gives this error:

The "LinkAssemblies" task failed unexpectedly.
System.IO.FileNotFoundException: Could not load assembly 'SmartLyrics, Version=0.0.0.0, Culture=neutral, PublicKeyToken='. Perhaps it doesn't exist in the Mono for Android profile?
File name: 'SmartLyrics.dll'
   at Java.Interop.Tools.Cecil.DirectoryAssemblyResolver.Resolve(AssemblyNameReference reference, ReaderParameters parameters)
   at Java.Interop.Tools.Cecil.DirectoryAssemblyResolver.GetAssembly(String fileName)
   at Xamarin.Android.Tasks.LinkAssemblies.Execute(DirectoryAssemblyResolver res)
   at Xamarin.Android.Tasks.LinkAssemblies.Execute()
   at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()
   at Microsoft.Build.BackEnd.TaskBuilder.<ExecuteInstantiatedTask>d__26.MoveNext() SmartLyrics         

And even if I build successfully, the layout doesn't get included in the Resources.

I'm using VS2019 16.1.1

All the answers for this error I've seen are for different variations of it, like The "LinkAssemblies" task failed unexpectedly. System.NullReferenceException: Object reference not set to an instance of an object. or The "LinkAssemblies" task failed unexpectedly. Xamarin.Android.XamarinAndroidException: error XA2006: Reference to metadata item 'System.Void Android.Widget.AbsListView.

The answer to those seems to be to change the target Android version to API 21, but that does not work for me. I didn't find any other answers but I also tried cleaning the solution and then building. Before this error, when a resource didn't get included when building, restarting VS or my computer worked, but this time it does nothing.

Another StackOverflow answer says to add the missing reference to my project References. But in my case this missing reference seems to be my own project.

LyricsViwerActivity.cs that contains the SetContentView for the new layout:

[Activity(Label = "LyricsViwerActivity")]
    public class LyricsViwerActivity : Activity
    {
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            SetContentView(Resource.Id.lyrics_viwer);
        }
    }

When including SetContentView(Resource.Id.lyrics_viwer); VS shows a 'Resource.Id' does not contain a definition for 'lyrics_viwer' error, which is expected since it didn't include the layout in Resources for whatever reason.

androidWG
  • 43
  • 1
  • 7

1 Answers1

0

I think all you need to do is change

SetContentView(Resource.Id.lyrics_viwer);

to

SetContentView(Resource.Layout.lyrics_viwer);

as SetContentView requires a Layout resource.

Robert Bruce
  • 1,088
  • 1
  • 13
  • 17