简体   繁体   中英

Xamarin 'Resource.Layout' does not contain a definition for '*' Error

Required Android Support Libraries

The controls in the suite require specific Xamarin Android Support Libraries to render correctly on Android.

Here are listed the common requirements for all Android projects that use our suite:

The minimum required version of Xamarin Forms package is 3.4. The minimum required version of all Xamarin Android Support Libraries is 27.0.2.1. Here are listed all packages:

Xamarin.Android.Support.v4
Xamarin.Android.Support.Design
Xamarin.Android.Support.v7.AppCompat
Xamarin.Android.Support.v7.CardView
Xamarin.Android.Support.v7.MediaRouter
Xamarin.Android.Support.Vector.Drawable
Xamarin.Android.Support.Animated.Vector.Drawable
Xamarin.Android.Support.v7.RecyclerView
Xamarin.Android.Support.v8.RenderScript 

The target Android version of the Android project should be Android 8.1 (API level 27) or greater.

The corresponding target Android version Android SDK has to be installed in order to use the required support libraries (install from the Android SDK Manager)."

Followed this and still receiving the two errors:

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

Tried uninstalling and reinstalling SDK's, SDK Tools, SDK Platform-Tools, SDK Build Tools, Android Emulator, LLDB, NDK, Extras, and SDK Patcher Applier v4 using the Android SDK manager in Visual Studio.

Deleted bin/obj folders, restarted VS, clean, rebuilt.

The errors persist. How to fix Error CS0117 Xamarin 'Resource.Layout' does not contain a definition for '*'?

1>  C:\Users\...\MyApp.Android\MainActivity.cs(44,49,44,53): error CS0117: 'Resource.Layout' does not contain a definition for 'Tabbar'
1>  C:\Users\...\MyApp.Android\MainActivity.cs(45,47,45,52): error CS0117: 'Resource.Layout' does not contain a definition for 'Toolbar'

protected override void OnCreate(Bundle bundle)
{
_Instance = this;

TabLayoutResource = Resource.Layout.Tabbar; (LINE 44)
ToolbarResource = Resource.Layout.Toolbar;  (LINE 45)

base.OnCreate(bundle); (LINE 47)

CrossCurrentActivity.Current.Init(this, bundle); (LINE 49)
global::Xamarin.Forms.Forms.Init(this, bundle);

Metrics = Resources.DisplayMetrics; (LINE 52)
widthInDp = ConvertPixelsToDp(Metrics.WidthPixels); (LINE 53)
heightInDp = ConvertPixelsToDp(Metrics.HeightPixels);

LoadApplication(new App());
}

The answers differ between a variety of questions related to Android build errors such as this one. Now, for myself, the fix was to undo all changes to Packages.config and the project file itself, in my case Android.csproj . Worth mentioning, I see a new error: Ambiguity between 'Resource.Layout.Tabbar' and 'Resource.Layout.Tabbar' (and the same for Toolbar ) but it doesn't prevent building and deploying.

Another possible solution, noticed the Resources.designer.cs file existed in both the Resources folder and Resources\\drawable folder. Excluding the prior seems to have worked. Know not why there are two. Hope this helps someone else.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM