Introduction to Cross-Platform Mobile Development (XAM110)
One of the advantages to using Xamarin over the traditional platform-specific approach is the level of code-sharing you can achieve across iOS, Android, and Windows. In this class, we will explore ways to structure your shared code using Portable Class Libraries, .NET Standard libraries, and Shared Asset Projects. We will look at the pros and cons of each approach and see how to access platform-specific features in each model.
Upon completion you will be able to:
- Work with shared packages from NuGet
- Use Shared Projects to share code between platforms
- Use Portable Class Libraries to share code between platforms
- Share code using .NET Standard libraries
Course exercise download
Exercise materials are available from GitHub. The code can be cloned through a desktop Git client or downloaded directly as a ZIP file.
If you are using Windows, try to select a location with a shorter path length to make sure you don't exceed the 260 character limit.
Lecture
Here are the lecture slides.
Exercises
-
Exercise 1: Share code using a Shared Project
The goal of this exercise is to load data from a JSON file and display it in an existing Xamarin application. The code to manage loading the file will be shared between the platform-specific projects using a Shared Project.
-
Exercise 2: Share code using Portable Class Libraries
We will work on the same project we did in the previous exercise, but this time we will use a Portable Class Library to share our JSON data loading between the iOS, Android and Windows projects. We will be starting almost where you left off in the last exercise, without the Shared Project implementation, but the code in the platform projects has already been filled out.
-
Exercise 3: Share code using a .NET Standard library
To explore .NET Standard class libraries, we will implement some shared code within a few .NET Standard target versions to see how it affects the available APIs.
-
Exercise 4: Upgrade a Portable Class Library to .NET Standard
We will work on the same project we did in the previous exercise. To explore the interoperability of Portable Class Libraries and .NET Standard class libraries, we will migrate our code from the MyTunes PCL library to our library targeting .NET Standard.
Additional resources
Popular components
Here are some popular open-source projects from Xamarin, you can install these into your applications using NuGet.