8

I've created a basic xamarin.forms project (with PCL code sharing strategy) and I'm getting error for the following two lines in MainActivity::OnCreate()

TabLayoutResource = Resource.Layout.Tabbar;
ToolbarResource = Resource.Layout.Toolbar;

CS0117 'Resource.Layout' does not contain a definition for 'Tabbar'
CS0117 'Resource.Layout' does not contain a definition for 'Toolbar'

The resource files exist as Resources\layout\Tabbar.axml and Resources\layout\Toolbar.axml and the build action for both of them is set to AndroidResource.

I suspect there is something wrong with my android SDK installation. Currently the following packages are installed:

enter image description here

But the Run button in Visual Studio 2015 still is showing Android 6.0 API 23 and it's not possible to change it:

enter image description here

I've also set the Target Framework version of the Android project to 7.1:

enter image description here

The project structure is as the following:

enter image description here

I've followed this tutorial step by step to create the sample project.

How can I get the error fixed?

B Faley
  • 17,120
  • 43
  • 133
  • 223

2 Answers2

5

The problem seems in API installed. It is still a little mystery for me which APIs must be installed but deleting the build tools 24 and installing build tools 26.0.1 fixed the issue for build.

Then installed NDK which was missing and set path in Xamarin options. Now 2 options are available for computers supporting HAXM and/or Hyper-V

  1. HAXM. Disable Hyper-V. Then change emulator setting in AVD manager which were not created and download an Itom image for emulator using Android SDK. Download and install HAXM. You are ready.
  2. Enable Hyper-V. Download and install Hyper-V VS emulators. Run it and create emulator(s) virtual machine(s). You are ready.

Run your app.

Yuri S
  • 5,355
  • 1
  • 15
  • 23
1

This happened to me when I included two files into "layout" folder: Tabbar.axml and Toolbar.axml. Following the Xamarin documentation at: https://learn.microsoft.com/en-us/xamarin/xamarin-forms/platform/android/appcompat-material-design

I solved the problem just right clicking in those files, selecting Properties and changing the Build Action to AndroidResource.

Sérgio Damasceno
  • 657
  • 1
  • 8
  • 18
  • When you include a file in layout folder, VS adds the xml extension and the Build Action is AndroidResource. If you change the extension to axml, the Build Action is changed to Content. That´s the problem! – Sérgio Damasceno Mar 01 '20 at 15:26