Setting up for Success: Building a Project with Xamarin
An important part of being a software engineer at our company is to continuously push the boundaries of what we can contribute. The engineers at Prolific have typically worked in a native environment—Android using Kotlin and Java, and iOS using Swift and Objective C—but if we didn’t try out new approaches to app development, we would be doing ourselves and our potential partners a great disservice. With this in mind, a natural progression in app development is sharing code across mobile platforms, which can be an amazing opportunity for developers to maximize their efforts. While native app development is our preferred path for mobile app development, we are always striving to expand our skill set and explore different methods that could provide value to our partners.
In the excitement of trying something new, we made a few assumptions about what working with Xamarin would be like. However, the benefits of any new platform do not come without a learning curve. Some of the challenges we encountered turned out to be bigger obstacles than we had prepared for. Xamarin may seem to pass the duck test, but things are often more complicated than they seem. There’s no perfect way to anticipate bugs and blockers, but we learned a few critical ways to set a foundation for success in Xamarin for anyone unfamiliar with the platform. Here are some tips to get the best out of the framework.
Start with an experienced native team!
Hiring for a cross-platform project? Hire developers with mobile development experience! Android and iOS platform knowledge is truly invaluable. Despite Xamarin helping to abstract away some of the native implementation and allowing the developers to share common code, most of the application will still need to be written with a native context in mind. That’s where mobile developers will shine. Any good developer should be able to learn C# fairly quickly, but knowing the development process for a mobile application is something that is hard to learn on the job.
Have an internal technical discovery to see if Xamarin is right for you
When deciding to try a cross-platform solution, there were a few options explored (React Native, Flutter, and Xamarin), but the obvious choice for our first foray into cross-platform was Xamarin. Why? Xamarin leverages native APIs, it’s written in C#, a ubiquitous and easy language for our developers to learn, and it’s a proven framework with shipped apps on both Android and iOS. The decision to use Xamarin was one of familiarity; the platform allows developers to work in a native-like environment and also share code in a unified project. For the most part, this made the project run smoothly.
Build from beginning to end first
Once you’ve decided on Xamarin, build out a test application from beginning to end. This includes creating the project, making a build process, implementing a few relevant features, and releasing it on the App Store. We found it’s best to focus on what prototyping makes the app special—implementing the core features and see how development goes. We continuously found blockers throughout the timeline of the project—from project setup, general bugs, to release issues—so do a thorough job! Getting a sense of what is coming will better prepare you for timeline pitfalls and make production painless.
Learn NuGet and the Xamarin build process
Xamarin uses a package manager called NuGet, which was extremely user-friendly and easy to use, but ultimately different and not exactly analogous to CocoaPods or Gradle. We were not internally familiar with NuGet, and while it wasn’t the biggest challenge of the project, it definitely was a blocker at some points. Unfortunately, packages were often out of date, poorly documented, and some didn’t even work. If we had known this was the case, we would have leveraged the ability to port Java to C# (for Android), discussed alternatives to packages we often use, or contacted the package owners and asked them to update their libraries.
Choose the right IDE for you
One of the larger learning curves had little to do with the code, but rather the development environment. Cross-platform tools are less polished and less supported than native tools. As the codebase grew larger and things became more and more complicated, the tools started to become less and less reliable. Restarting the IDE was a daily, if not hourly, occurrence, and build times were often frustratingly long. Updating dependencies led to obscure bugs and build failures, so we were forced to stop upgrading our IDE because breaking changes were a regular occurrence. We couldn’t leverage code swap tools like Instant Run on Android, and with a poor graphical editor in Visual Studio, small UI changes became large endeavors. With a focus on high-quality apps with great design at Prolific, having a poor UI editor with slow code changes added a lot of development time, so learning the IDE’s shortcuts and strengths should be a top priority to make the best use of your time. In choosing the right IDE for you from the start, Rider and Visual Studio are your best options.
Work out code standards early, but don’t stress them
What makes good code in Xamarin? What should we be looking out for? How do we maximize the capabilities of Xamarin to make development faster? One of the best things about learning Xamarin is it forced us to relearn what we thought we already knew. We learned C# language features and code standards along the way, but it’s probably best to do a deep dive into all the language features C# has to offer before you start a production project. It’s a wonderful, robust language and a fantastic tool to learn for all sorts of development outside of the mobile space.
Sharing code in a single project can be an amazing opportunity for developers to maximize their efforts when developing for Android and iOS if they approach it the right way. There are many unknowns in learning any new method, including obscure bugs and other issues that can become frustrating and block production. Give yourself time to work these out, and don’t get frustrated. In spite of its native feel and ease of using C#, Xamarin is its own platform that requires developers to be creative in their approach and make an effort to step outside the native mindset. If you put the right foundation in place, Xamarin can be an incredible tool to build a cross-platform app.