Tuesday 5 February 2019

Xamarin Empty Apps is not working

Xamarin Empty App is not working


When you decide to learn cross-platform mobile development, and then you choose Xamarin, so welcome to Microsoft world where everything depends on something.


It is too frustrating when you try to build a new project and it is not working, compilation errors every where.

Lets go straight to creating and building projects:

First lets see the different environments I have faced:
  • The best environment: 
    • Visual Studio 2017 last stable release (15.9.6 or more)
    • Windows 10 version (build) is at least 1803, referring to Microsoft: Microsoft Docs
    • Highlighting the .NET framework version to be 4.7+
  • Another environment 
    • Visual Studio 2017 last stable release (15.9.6 or more) 
    • Windows 10 version (build) is 10240
    • .NET framework 4.6+  and cannot be update because of the windows build


    The first environment you will not face any issues I hope, lets start project for the the other environment
    Important note: in the second environment, don't count on Visual Studio's Android SDK 
      I had to setup Android Studio and used it to setup Android SDK.


Cross-Platform Projects

Shared Project

  1. Open Visual Studio and create a new project



  2. Choose Shared Project



  3. As you can see, boom errors every where:



    1. 'Forms' does not exist in the namespace 'Xamarin'
    2. The other Xaml components are also missing

.NET Standard

  1. Open Visual Studio and create a new project, and choose .NET Standard


  2. You will find everything is red, boom same errors everywhere but there are more



    1. System could not be found  😓
    2. Xamarin could not be found
    3. Could not load file or assembly netstandard



Solution:
  1. Go to Nuget packages for the solution
  2. Uninstall [Xamarin.Forms package]

  3. Install  [Xamarin.Forms package] - Version 2.5+, but below 3
    --------- explained in the conclusion

  4. Clean, rebuild and run
    Congratulations no errors  



Conclusion

Now we can list some recommendations that may help you to overcome Xamarin building problems or facing similar errors.
  • First recommendation of course that you update your windows and .NET Framework
  • It is preferred that you install [Android SDK] using (Android Studio) before installing Xamarin Mobile platform
  • If you have (DotNet Framework) lower than 4.7 , Then use [Xamarin version] lower than 3, as I think that Xamarin 3+ is not supporting lower .NET Frameworks
Now You are ready for Xamarin development Happy Coding 😉