When I create a new blank cross-platform project in Visual Studio 2017 I get about six errors. All on 'MainActivity.cs' page. I'm running VS2017 that updated to support Core 2.1. I'm not sure what I need to install or change to fix this.
I'm using
C:\Program Files\Java\jdk1.8.0_171
C:\Program Files (x86)\Android\android-sdk
and under tools and extensions, everything is up to date.
namespace HelloWorld.Droid
{
[Activity(Label = "HelloWorld", Icon = "@mipmap/icon", Theme =
"@style/MainTheme", MainLauncher = true, ConfigurationChanges =
ConfigChanges.ScreenSize | ConfigChanges.Orientation)]
public class MainActivity :
global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity
{
protected override void OnCreate(Bundle savedInstanceState)
{
TabLayoutResource = Resource.Layout.Tabbar;
ToolbarResource = Resource.Layout.Toolbar;
base.OnCreate(savedInstanceState);
global::Xamarin.Forms.Forms.Init(this, savedInstanceState);
LoadApplication(new App());
}
}
}
errors(I get these errors every time I create a blank project)
Error CS0103 The name 'LoadApplication' does not exist in the current context Error CS0234 The type or namespace name 'Android' does not exist in the namespace Error CS0115 'MainActivity.OnCreate(Bundle)': no suitable method found to override Error CS0103 The name 'ToolbarResource' does not exist in the current context Error CS0103 The name 'TabLayoutResource' does not exist in the current context Error CS0234 The type or namespace name 'Forms' does not exist in the namespace 'Xamarin.Forms'
I'm new to Xamarin and I tried to add references to my project but I'm not sure which of the 3 projects to add references or what references I need.
In the end, doing the below solved the issue:
what I did was went to help in VS2017
and updated to 15.9.6
and it recommended an update to Android SDK
. So I updated it all and cleaned and rebuild project and that fixed the issue. When I first ran the project it told me some Android references need updating
and I updated from the error list and in the NuGet
panel. And it worked