Search icon
Subscription
0
Cart icon
Close icon
You have no products in your basket yet
Save more on your purchases!
Savings automatically calculated. No voucher code required
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
$9.99 | ALL EBOOKS & VIDEOS
Over 7,000 tech titles at $9.99 each with AI-powered learning assistants on new releases
Learning Xamarin studio
Learning Xamarin studio

Learning Xamarin studio: Learn how to build high-performance native applications using the power of Xamarin Studio.

By William Smith
$25.99 $9.99
Book Aug 2014 248 pages 1st Edition
eBook
$25.99 $9.99
Print
$43.99
Subscription
$15.99 Monthly
eBook
$25.99 $9.99
Print
$43.99
Subscription
$15.99 Monthly

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
Buy Now
Table of content icon View table of contents Preview book icon Preview Book

Learning Xamarin studio

Chapter 1. Installing and Setting Up Xamarin Studio

Software developers are very selective with the tools they work with. We take the time to evaluate our goals and examine our available options. Then, we compare these options to our goals to determine the best tool for the task at hand. Xamarin Studio is one tool we can choose for cross-platform development using .NET. It is not a one-size-fits-all solution for all of your development needs. Instead, it's a specialized tool that allows .NET developers to efficiently create applications that can run on multiple platforms while using the technologies they are already familiar and experienced with.

The purpose of this chapter is to help you install and set up Xamarin Studio, as well as the ancillary tools you will need to effectively develop in a cross-platform environment.

In this chapter, we will cover the following topics:

  • Xamarin Studio pricing plans

  • Xamarin Studio platform options

  • Installing Xcode and the iOS SDK

  • Installing Xamarin Studio

  • Apple Developer Program

  • Google Play Developer Program

  • Installing simulators and emulators

  • Improving AVD performance

  • Setting up test devices

  • Setting up source control

  • Additional resources for cross-platform developers

Xamarin Studio pricing plans


As of June 2014, Xamarin offers four subscription plans for developers to choose from: Starter, Indie, Business, and Enterprise. The details and prices of these plans presented here are accurate as of the time this was written, but be aware that they are subject to change.

Starter

At the entry level, Xamarin offers the Starter edition of Xamarin Studio. In many respects, this edition is similar to a fully functional trial except that there is no expiration date on the license. This edition is perfectly suitable to demonstrate the guides and walkthroughs presented in this text. At this point, you might ask yourself why you would need to actually spend money and enroll in one of the professional editions. For most people, the reason is that the Starter edition is limited in three very important aspects.

First, this edition limits the size of your compiled packages to 64 KB. This is so limited even some of the demonstration apps bundled with the Xamarin Studio installation are too large to be run. Secondly, the Starter edition does not allow development from within Visual Studio. Finally, this edition does not offer access to downloadable components and permits calls to third-party native libraries. For example, while developing a simple Android application using the Starter edition, I wanted to implement the IParcelable interface, only to learn that my subscription did not permit me to include the necessary module. I promptly upgraded my plan. Well played, Xamarin.

Indie

Next up is the Indie edition. Similar to the Starter edition, Indie is fully functional. However, with the Indie edition you are permitted to call out to third-party native libraries. More importantly, your compiled application size is no longer limited to 64 KB, and it can effectively be as large as your target device can handle. Without this limitation, Indie also permits building apps using the Xamarin.Forms framework introduced in Xamarin 3. Although the Indie edition does not allow System.Data.SqlClient to be referenced in your project, you may still integrate other third-party components such as sqlite-netORM to provide data store functionality.

It's worth pointing out that, similar to the Starter edition, Indie does not allow you to develop within Visual Studio. If developing directly in Visual Studio is a critical requirement for your process, then the Indie edition isn't for you. However, all of the independent Xamarin developers that I am acquainted with, myself included, use this edition and they are satisfied.

Business

Cited as being the most popular option, the Xamarin Business edition offers everything that the Indie edition offered, plus several additional features. First, you can develop, deploy, and debug from within Visual Studio. Secondly, you have access to private e-mail support from Xamarin. Finally, and arguably most importantly, this plan has support for in-house deployment, headless builds, WCF, and System.Data.SqlClient. Code troubleshooting assistance from Xamarin experts is also available with this edition at an additional cost.

Note that if you are a company or an incorporated entity with five or more employees, you may not purchase the Indie edition but must purchase the Business or Enterprise editions instead.

Enterprise

Finally, the Enterprise edition offers some additional perks in the form of supplementary support options, bundled prime components, access to Hotfixes, and a dedicated Technical Account Manager. This plan is topped off by a guaranteed one-day response service-level agreement, which can be a valuable asset when your team is facing a tough challenge under a tight deadline.

Understanding the pricing structure

Xamarin editions are not based on licensing the development studio itself, but rather on the platform the developer will be working with. This means if you or your team wants to develop iPhone apps, you will need to purchase one of the plans for the iOS platform. This license will permit you to develop any type of iOS app from iPhones to iPads or iPod Touch, but it will not permit you to develop applications for Android devices. In order to develop in both iOS and Android, you will need to purchase two plans. This is also true for the Mac platform.

These plans are subscriptions that must be renewed annually. If you decide not to renew the subscription, Xamarin Studio will continue to function and you will still have access to your development platform and your work. However, you will no longer have access to new releases or ongoing support.

Additionally, Xamarin offers special discounts to various groups. To inquire about the specifics of these offers, you will need to contact Xamarin sales directly:

  • Open source projects that plan to contribute to the Xamarin framework can receive complimentary non-commercial licenses for Xamarin products.

  • MSDN subscribers can get a 30 percent to 50 percent discount for their annual subscription costs.

  • Businesses purchasing a large number of licenses can receive a volume discount.

  • Start-ups less than 3 years old and small businesses with fewer than 20 employees can get special discounts as well.

  • Finally, the academic discount applies to professors teaching courses on Xamarin and any students enrolled in accredited institutions. This discount allows eligible developers to purchase a Business edition (without e-mail support) of Xamarin.iOS, Xamarin.Android, and/or Xamarin.Mac for $99.

An example company

As an example, let's assume a company has 14 employees, seven of whom are developers, and this company is endeavoring to create a cross-platform mobile application. One developer will be focusing on writing the shared logic using Visual Studio, two will be developing the Windows Phone UI, another two will develop the Android UI, and the remaining two will develop the iPhone UI. Three of these developers will not need a Xamarin license, while two will require an iOS platform license and two will require an Android platform license. Since this company has more than five employees, only the Business and Enterprise plans are acceptable. Therefore, at a minimum, this company must procure four business plan subscriptions at an annual cost of roughly $4,000.

This may seem like a steep price for a small company to absorb, but it's really quite cost effective. If you compare this subscription cost to the cost of merely recruiting four full-time specialist developers, you will immediately see the advantage that Xamarin Studio provides to your organization.

Tip

Do you need more information? For more specific details on the pricing plans, see the Pricing section of Xamarin's FAQ at http://www.xamarin.com/faq.

Xamarin Studio platform options


Xamarin Studio enables .NET developers to build applications that target three distinct platforms: Android, iOS, and Mac. Xamarin Studio is the Core Integrated Development Environment and is required for development on any of these target platforms. In addition to Xamarin Studio, you will need to install the specific plugin for your target platform. These plugins are detailed in the following sections.

Xamarin.Android

The Xamarin.Android package is required to develop applications that target the Android platform. Android development with Xamarin can be performed on any Windows PC or Mac that meets the minimum system requirements. The Android SDK is required for development, and it will be downloaded during the Xamarin Studio installation.

Xamarin.iOS

Xamarin.iOS is required to develop applications that target the iOS platform. The iOS development with Xamarin can be performed on any Windows PC or Mac that meets the minimum system requirements. However, in order to develop on a Windows PC a networked Mac is required as a build and deployment machine. Xcode and the iOS SDK are also required for development, and they must be installed prior to installing Xamarin.iOS. Additionally, at the time of writing this Xamarin Studio is unable to generate a proxy file for WCF services. Therefore, if you intend to utilize the WCF services in your iOS application, you will need a Windows machine to generate the proxy files.

Xamarin.Mac

Xamarin.Mac is required to develop applications that target the Mac platform. At the time of writing this, Mac development with Xamarin can only be performed on a Mac running at Lion (OS X 10.7) or higher, which meets the minimum system requirements. Xcode is also required for development, and it must be installed prior to installing Xamarin.Mac.

Installing development components


Before we begin installing Xamarin Studio and the necessary supporting components, it's important to note that this book's perspective is developing iOS, Android, and Mac applications on a Mac. This means that the names and conventions will be those you'll see when working with Mac OS X. In most cases, the differences between a Mac OS X environment and a Windows environment will be negligible and, therefore, I won't discuss them. However, in the cases where the differences are significant, or where there is a different process to be followed, the details will be pointed out and highlighted. In some cases, entire portions of the book (such as the Installing the Visual Studio plugin section in Chapter 4, Plugins, Templates, Libraries, and Files) will be dedicated to the Windows platform environment.

Installing Xcode and the iOS SDK


Xcode is Apple's premier (and free for all OS X users) integrated development environment to develop Mac, iPad, iPhone, and iPod Touch applications. Additionally, the iOS SDK comes bundled with Xcode upon installation. Since the Xcode application's release cycle closely matches that of the Mac and iOS platforms, you as a developer can expect to always have access to the tools needed to develop applications that target the latest iOS platforms.

Although Xamarin Studio 5 comes bundled with its own interface builder, this tool only supports storyboard development as of the time this was written. Xcode provides an interface builder to create graphical user interfaces for iOS and Mac development using storyboards as well as XIB files. Also, the package includes Instruments, which is a graphical user interface tool for application performance analysis and visualization. We will discuss Instruments more in Chapter 7, Testing and Debugging.

Note

If you do not intend to develop iOS applications, you may skip this section for now and come back to it whenever you're ready. However, you will not be able to install Xamarin.iOS or Xamarin.Mac until Xcode and the iOS SDK have been installed.

Installing Xcode from the App Store

To install Xcode, perform the following steps:

  1. Open the App Store from the Dock or Finder.

  2. If you have not already done so, log in by navigating to Store | Log In and entering your credentials.

  3. If you are visiting the App Store for the first time, you will need to create an account. For details on creating an App Store account, see the Apple support documentation at http://support.apple.com/kb/HT4479.

  4. In the spotlight, type xcode and begin the search.

  5. Select the Xcode Developer Tools app and then click the Install App button. This will begin the download and initial installation process, as shown in the following screenshot:

Tip

Xcode is not a simple application, and the initial download is just over 2 GB in size. Therefore, depending on your connection speed, you may need to wait for some time. If you get bored and want to see how things are progressing, hover over launchpad in the Dock and you will see the current download/installation progress. Alternatively, you can open launchpad and view the progress there as well.

Installing Xcode manually

On the other hand, if you don't have an App Store account or for some reason you don't want to use one for this purpose, you can also download the Xcode installer manually from https://developer.apple.com/xcode/.

Perform the following steps to download Xcode manually:

  1. When you arrive at the download page, you will see the Download Xcode 5 for free. section as shown in the preceding screenshot.

  2. Click the View downloads link.

  3. When you reach the program list, type xcode 5 in the search field and hit Enter.

  4. Your search results should include the latest Xcode 5 installer, as shown in the following screenshot:

  5. Click the download link to the right-hand side of the product description.

  6. Once the download is complete, open the file and continue.

  7. Follow the prompts.

Finishing the Xcode installation

Once the download has completed, we will still need to open Xcode from the launcher to begin to finalize the installation. The steps are as follows:

  1. Open the launcher.

  2. Open Xcode.

  3. Accept Xcode and iOS SDK License Agreement.

  4. When prompted, enter your system credentials to give the installer permission to continue.

Installing Xamarin Studio


Once Xcode has finished installing, the only prerequisite you have is the Xamarin Studio Unified Installer, which could not install on its own. All of the other prerequisites for cross-platform development, such as the Java SDK, the Android SDK, and the Mono Framework, will be installed concurrently with Xamarin Studio as needed based on the products you choose. Let's begin installing Xamarin Studio:

  1. First, we need to download the Xamarin unified installer from http://www.xamarin.com/download.

    Note

    If you haven't purchased a subscription yet, or if you simply want to download the Starter edition, you can just tell them about yourself and click Download Xamarin for your platform. However, if you have created an account or you have already purchased a subscription, you will need to click Sign In on this page and follow the link to download Xamarin Studio on the landing page that follows.

  2. If you are trying out Starter edition anonymously, your download should begin automatically. If you have logged in, you will need to click Download under your highlighted current plan.

  3. Once the Xamarin Studio Unified Installer finishes downloading, you need to run the installer.

  4. When the splash screen appears, double click on the Install Xamarin.app icon.

  5. When the installer opens, you will need to review the Xamarin software license. If you agree to the terms, click the Accept button to proceed.

  6. Next, you need to select the plugins you want to install. In my case, I selected all three, as shown in the following screenshot. However, you should choose the plugins you intend to work with.

  7. If you chose to install Xamarin.Android on the next screen, you will be asked to configure the installation to specify where the Android SDK will be installed, as shown in the following screenshot:

  8. After reviewing the prerequisites that need to be installed, take a moment to review the additional licenses as they are presented. If you agree to the terms, click Accept to proceed.

  9. Once you have accepted the last batch of licenses, you have an opportunity to take a short break while the installation proceeds. As you can see from the following screenshot, Xamarin Studio is another large application:

    Note

    While the Xcode installation was self-sufficient after it was set in motion, the Xamarin Studio installation may require you provide your system credentials for some of the components being installed. So once the installation starts, you can go ahead and take that break you've been looking forward to. However, just be sure to check in on your machine from time to time.

  10. Once the installation is complete, please take a moment to review the progress report before closing the installer.

    Note

    If your installation experiences any common errors or some components fail to install completely, just restart the installer. Those components successfully downloaded and installed will persist, and the installer won't try to download them again. For example, during my first attempt Xamarin.iOS failed to download. I restarted the installer and after a few minutes, the component was up and running.

You have now installed the most basic tools you need for developing in Xamarin Studio. Now, let's begin by exploring the various Apple Developer Programs and the Google Play Developer Program.

Tip

Having developed and maintained applications for both iOS and Android devices, I learned that the two platforms are very different—not only in terms of functionality, but also in development process. If you are new to developing for mobile devices in general, I suggest that you choose one platform to focus on and work through that development track for the remainder of this text. Then, once you are comfortable developing for that platform, come back and work through the opposing platform.

Furthermore, it is my opinion that iOS is the easiest platform to learn for a first-time Xamarin user. Nevertheless, please make your decision based on your specific goals.

Apple Developer Program


It's not technically necessary to have an Apple Developer Program account to develop iOS or Mac applications. However, you will need to have one if you intend to release your app to the App Store. Additionally, you won't be able to test your application on your own personal mobile devices without an active account, specifically an iOS Developer Program account. This may seem unfair at first, but keep in mind that an active account enables you to create a provisioning profile for your application. A provisioning profile is a certificate that lets your device know that your application comes from a trusted source and is permissible to execute. We will discuss provisioning profiles in more detail later in this chapter.

As stated, the iOS Developer Program account lets you deploy applications to your iOS devices for testing and to the App Store for sale once the application has passed Apple's QA process. Apple also offers the Mac Developer Program to develop Mac applications. Again, you can develop Mac apps using Xamarin Studio without holding a Mac Developer Program account. The difference is that you can test your application on your physical machine without holding an active account. You will only need an active Mac Developer Program account if you intend to release your app to the App Store.

Each of the developer program accounts carries an annual subscription cost of $99, whether you are an individual developer or a business entity with multiple developers. Under both programs, Apple will also collect 30 percent of every App Store sale. The iOS Developer Program also has an Enterprise class for businesses planning to develop apps exclusively for in-house purposes. This subscription costs $299 per year, presumably because these apps will not produce any revenue for Apple through sales in the App Store.

Tip

Why don't I just jailbreak my device?

While I've heard rumors that it is possible to jailbreak your mobile device to enable deployment testing without having an active iOS Developer Program account, what would be the point?

The security you are removing is there to protect your equipment. More importantly, you will still need to get an account at some point before you can distribute your application to paying customers. Without an account, you won't even be able to easily distribute your application to testers or a contract customer using TestFlight. In my opinion, $99 a year is a small price to pay to maintain your integrity and professional reputation.

The steps required to subscribe to either the iOS or the Mac Developer Programs are the same. Also, the only difference between subscribing as an individual versus a business entity is that a business will require a free D&B D-U-N-S Number. D-U-N-S Numbers are a unique nine-digit identifier for businesses issued by Dun & Bradstreet. This identifier has become the standard to track businesses worldwide. Many businesses, including most of the Fortune 500 companies, require a D-U-N-S Number when you are applying to do business with them as a supplier, contractor, or consultant. If your business does not currently have a D-U-N-S Number, you will have an opportunity to obtain one prior to creating your developer program account.

Note

Be aware that the process of obtaining a D-U-N-S Number is not automated, and it may take several business days to finalize once you have completed and submitted the brief application.

Let's walk through the process of subscribing to an iOS Developer Program account now.

Note

If you do not intend to develop iOS applications, you may skip this walkthrough for now and come back to it whenever you're ready.

Perform the following steps to subscribe to an iOS Developer Program account:

  1. Open your browser and go to https://developer.apple.com/programs/.

  2. Click on the iOS Developer Program section.

  3. Click the Enroll Now button.

  4. Click the Continue button.

  5. You will have the option to enroll with your current Apple ID or create a new ID for this purpose. For this demonstration, we will assume you are using your current ID. Click the Continue button next to your current ID.

  6. Decide whether you are enrolling as an Individual or as a Company and click the appropriate button.

  7. For whichever plan you choose, fill out the required information and click the Continue button.

  8. Choose the programs you wish to subscribe to and click the Continue button.

  9. Review your information and click the Continue button.

  10. Review any terms and conditions presented. If you agree to the terms check the boxes and click the I Agree button.

  11. Review your shopping cart and click the Buy Now button.

  12. Activate your new account.

Google Play Developer Program


Google offers a developer program for Android devices called the Google Play Developer Program. Like the Apple programs, it is not necessary to have a Google Play Developer Program account to develop Android applications. Unlike the iOS program, you can deploy to your personal devices without an active Google Play Developer Program account. You will only need a Google Play Developer account if you intend to sell your app on the Google Play Store. At the time of writing this, Google charges a one-time fee of $25 for a developer program account for an individual or a business.

Note

If you do not intend to develop Android applications, you may skip this walkthrough for now and come back to it whenever you're ready.

Let's walk through the process of subscribing to a Google Play Developer Program account now:

  1. Open your browser and go to https://play.google.com/apps/publish/signup/.

  2. Sign in with your Google account and click the Continue button.

  3. Review the Google Play Developer distribution agreement. If you agree to the terms select the checkbox and click the Continue to payment button.

  4. Enter your payment information and click Accept and continue.

  5. Once your payment has been accepted, you will need to create your Developer Profile. Enter your name, e-mail address, website (if applicable), and phone number and click the Complete registration button.

Once you have completed the registration, you will be redirected to the Google Play Developer Console. We will discuss the Developer Console in more detail in Chapter 8, Deployment.

Setting up simulators and emulators


Technically speaking, simulators and emulators are different technologies. Within the context of our discussions on mobile application testing, it is important to note that Android testing is performed on an emulator, while iOS testing is performed on a simulator. At first this may seem like pure semantics, but in fact it is a very critical distinction for a mobile developer to understand.

Android emulators attempt to emulate the characteristics and environment found on an actual device. This means if your device has 2 GB of RAM, then the emulator will likewise be limited to 2 GB of RAM, hence the term emulator. An iOS simulator, on the other hand, has access to your full system resources. This means that if your Mac has a 32 GB RAM with a 2.3 GHz i7 quad-core processors, so does that iPhone simulator you're testing on, even though a true iPhone device does not have 32 GB of RAM or an i7 processor. Do you see the potential problems presented by this design?

No matter how intense your application is, or how much processing power it requires, there will almost always be an ample supply of resources available to the simulator. Inside the simulator, your application will be lightning fast and, unless you have a leak somewhere in your code, it will probably never run into memory issues. This is not a real-world testing environment, which is why the iOS testing environment is referred to as a simulator.

Beyond these differences, at least for the purpose of our discussions of virtual mobile application testing, let's just assume that the remaining differences truly are semantic. Additionally, the Android SDK refers to an emulator as an Android Virtual Device (AVD). So, in the further chapters of this book, when we are testing iOS applications in a virtual environment, we are using a simulator. Also, when we are testing Android applications in a virtual environment, we are using an emulator or AVD.

iOS simulators

Luckily for us, the latest iOS simulators come bundled with Xcode and require very little, if any, setup before they can be used. This means you can test iOS 7 simulators for iPhone, iPhone, iPad, and iPad Mini devices right out of the box. However, if you want to make your apps backward compatible with an iOS 6 device, which is an entirely reasonable expectation, you will still need to download the iOS 6.1Simulator package.

To install the iOS 6.1 Simulator, perform the following steps:

  1. Open Xcode.

  2. Navigate to Xcode | Preferences.

  3. Select the Downloads tab and you will see the following window:

  4. In the Components group, click the arrow to the right of iOS 6.1 Simulator.

  5. Once the download is complete, the new simulators will be available inside Xamarin Studio.

Android emulators

Ideally, setting up an AVD for various Android devices should be simple. As is often the case in development, ideal conditions are not the norm. Since there are so many types of devices and configurations that can run the Android OS, it is not feasible to simply include boxed AVDs for every one of them. As you are about to see, the file sizes associated with even one boxed AVD image makes the idea of simply including them all with the installation of the SDK impossible to implement. Therefore, it is typically left up to the developer to create an AVD definition and image to match the target platform. Although a detailed walkthrough of every permutation of Android version and device configuration is beyond the scope of this book, let's look at setting up an AVD for the popular Nexus 7 tablet as well as the Samsung Galaxy S4 as typical examples.

Creating a Nexus 7 AVD using the AVD Manager

We'll start by creating a user-defined Nexus 7 image. In the case of the Nexus 7, there is a basic image prepackaged with the SDK installation. Assuming we want to create a Nexus 7 image with a different configuration for our testing, we can use this packaged image as a starting point for creating our own. We will accomplish this by cloning the existing image.

To create a Nexus 7 user image through cloning, perform the following steps:

  1. Inside Xamarin Studio, navigate to Tools | Open AVD Manager.

  2. Select the Device Definitions tab.

  3. Select the Nexus 7 by Google image.

  4. Click Create AVD.

  5. Change the AVD Name field by entering name for the AVD.

  6. Leave the Device value as default.

  7. From the Target drop-down list, select Android 4.4.2 – API Level 19. Your dialog should resemble the following screenshot:

  8. Leave all of the other settings at their default values and click the OK button.

Once the new user image has been created, it will be available for use during testing with Xamarin Studio.

Creating a Samsung Galaxy S4 AVD using the SDK and AVD Manager

Now, let's create a custom user image. For this walkthrough, we'll create a Samsung Galaxy S4 AVD. This device emulator is not bundled with the SDK, and in fact, it requires an additional SDK from Sony in order to be created.

To create a Samsung Galaxy S4 AVD, perform the following steps:

  1. Inside Xamarin Studio, go to Tools | Open SDK Manager.

  2. Once the SDK Manager opens, go to Tools | Manage Add-On Sites.

  3. Select the User Defined Sites tab.

  4. Click New.

  5. Enter http://dl-developer.sonymobile.com/sdk_manager/Sony-Add-on-SDK.xml in the field provided and click OK.

  6. Close the Add-on Sites dialog.

  7. Check whether the Sort by property at the bottom of the dialog window is set to API Level.

  8. Expand the Android 4.1.2 (API 16) group.

  9. Select the checkbox for Sony Add-on SDK.

  10. Scroll down and expand the Extras group.

  11. Select the checkbox for Sony Device Profiles.

  12. Click Install 2 packages.

  13. Once these packages are installed, you may close the SDK Manager.

  14. Inside Xamarin Studio, navigate to Tools | Open AVD Manager.

  15. Select the Device Definitions tab.

  16. Select the XPeria Z1 image.

  17. Click Clone.

  18. Insert Samsung Galaxy S4 in the Name field.

  19. Set the Buttons value to Hardware and your dialog should resemble the following screenshot:

  20. Click Clone Device.

  21. If the settings were accepted, the Clone Device dialog should close and you will be back at the AVD Manager. Return to the Android Virtual Devices tab.

  22. Click New.

  23. In the AVD Name field, enter a name for your AVD, for example, GalaxyS4_1.

  24. From the Device drop-down list, select the definition you just created. In my case, the definition is named Samsung Galaxy S4 (1080 x 1920: xxhdpi).

  25. From the Target drop-down list, select Sony Add-on SDK 2.1 (Sony) – API Level 16.

  26. For the Front Camera and Back Camera lists, choose how you would like to emulate the cameras. Your options are to not emulate them at all (None), emulate them through software (Emulated), or to use a webcam (Web Camera).

  27. Under the Emulation Options group, select the checkbox for Use Host GPU. Your dialog should resemble the following screenshot:

  28. Leave all the remaining settings at their default values and click OK.

  29. Review the various licenses that are presented. If you agree to the terms of each, click the Accept Licenses button.

Once the new user image has been created, it will be available for use during testing with Xamarin Studio.

Improving AVD performance


Once you've had the opportunity to work with one of the AVDs, you will notice right away that they are very sluggish during their initial startup, and only marginally faster on subsequent startups. This behavior is consistent on both Mac and Windows machines running Intel chipsets, but it seems to be especially true on Windows. However, don't be discouraged by this initial performance because there are steps that can be taken to significantly improve this.

Note

All of the performance measurements cited in this section are averages based on tests performed on my personal development machine. For example, I tested my user-defined Nexus 7 AVD and clocked an average initial start up time of just over 3 minutes, and an average subsequent start up time of just over 2 minutes. These average measurements will serve as the benchmarks for later testing and comparison.

Intel x86 Atom System Image

Most Android devices run ARM processors. Likewise, the out-of-the-box AVDs are based on the ARM system image called the APM EABI v7a System Image. Although the ARM processor architecture is highly efficient and suitable for mobile device applications, it is also quite different from Intel architecture. As a result, the ARM system image performs very poorly when emulated on an Intel chipset.

Intel is aware of this performance issue and has responded by creating its own system image called Intel x86 Atom System Image. This image was designed for the specific purpose of running AVDs on Intel-based machines, and it can significantly improve AVD startup and operational performance. The only drawback is Intel x86 Atom is not available for every target API level at this time.

Let's create a new AVD from scratch, but this time target the Intel x86 Atom System Image:

  1. Inside Xamarin Studio, go to Tools | Open SDK Manager.

  2. Once the SDK Manager opens, go to Tools | Manage Add-On Sites.

  3. Select the User Defined Sites tab.

  4. Confirm that the Android x86 System Image property exists.

    • If not, click the New button

    • Enter https://dl-ssl.google.com/android/repository/sys-img/x86/sys-img.xml and click OK

  5. Close the Add-on Sites dialog.

  6. Confirm that the Sort by property at the bottom of the dialog window is set to API Level.

  7. Scroll down and expand the Android 4.4.2 (API 19) group.

  8. Select the Intel x86 Atom System Image checkbox.

  9. Click Install 1 package.

  10. Once this package is installed, you may close the SDK Manager.

  11. Inside Xamarin Studio, go to Tools | Open AVD Manager.

  12. Select the Device Definitions tab.

  13. Select the Nexus 7 by Google image.

  14. Click the Create AVD button.

  15. In the AVD Name field, type AVD_for_Nexus_7_by_Google.

  16. From the Target drop-down list, select Android 4.4.2 – API Level 19.

  17. From the CPU/ABI drop-down list, select Intel Atom (x86). Now, your dialog should resemble the following screenshot:

  18. Leave all of the other settings at their default values and click OK.

Try using your new Nexus 7 AVD and compare the speed to that of the original, ARM-based AVD. You should see a marked improvement in both startup and operational performance.

Hardware Acceleration Execution Manager

So, you've tried out your new Nexus 7 AVD running on the Inter x86 Atom image. Now you're thinking, "This is good, but can it be better?". To coin a phrase, "Gentlemen, we can rebuild it. We have the technology."

If you are running a fairly up-to-date computer with an Intel chip that has Intel® Virtualization Technology enabled, you can utilize the Intel Hardware Acceleration Execution Manager (HAXM). HAXM is capable of easily improving performance by an order of magnitude. Coupled with an AVD built on the Intel x86 Atom system image, the improvement is almost astounding.

Note

Note that there is a specific hardware prerequisite to use this technology. Your machine, whether it is Mac OS or Windows, must have an Intel processor with support for Intel VT-x, EM64T and Execute Disable (XD) Bit functionality enabled in Basic Input/Output System (BIOS).

AXM can be installed in three steps. First, you need to make sure that virtualization technology is enabled in the BIOS. Then, you need to install the HAXM add-on through the SDK Manager. Finally, you need to run the executable for your system.

Since virtualization technology is typically turned on by default on most systems, we'll start by installing the HAXM add-on through the SDK Manager by using the following steps:

  1. Inside Xamarin Studio, go to Tools | Open SDK Manager.

  2. Once SDK Manager opens, go to Tools | Manage Add-On Sites.

  3. Select the User Defined Sites tab.

  4. Confirm that the Intel HAXM property exists.

    • If not, click the New button

    • Enter https://dl-ssl.google.com/android/repository/extras/intel/addon.xml and click OK

  5. Close the Add-on Sites dialog.

  6. Confirm that the Sort by property at the bottom of the dialog window is set to API Level.

  7. Scroll down and expand the Extras group.

  8. Select the Intel x86 Emulator Accelerator (HAXM) checkbox.

  9. Click Install 1 package.

  10. Once this package is installed, you can close the SDK Manager.

    Note

    You may have noticed that the HAXM entry in SDK Manager was listed as Installed when you were finished. This is just poor design on the part of the SDK Manager, in my opinion, because the package is not fully installed quite yet. To do this, we need to launch the HAXM executable.

  11. Open Finder (or Explorer in Windows) and navigate to <sdk>/extras/intel/Hardware_Accelerated_Execution_Manager/.

  12. From here, launch IntelHAXM.dmg (IntelHAXM.exe in Windows).

  13. Proceed through the HAXM installation process. When you reach the screen titled Memory Limit for Intel HAXM, it's best to just leave the default setting for now as you can go back and change it later if necessary. Setting this value too high initially can cause poor performance in other applications on your system while the HAXM is running.

    Note

    If during the installation you receive an error message stating that Intel® Virtualization Technology is not turned on, you will need to enable it in BIOS before you can proceed. Enter your system's BIOS settings, set Virtualization Technology: [Enabled], and then restart the executable.

At this stage, you should be enjoying much faster performance of your AVDs. In fact, HAXM can make those AVDs based on the Intel x86 Atom image run at near native speeds! Initial startup of the AVD takes around 25 seconds on my machine, while subsequent startups take around 17 seconds. There's still one more item we can tweak in our AVD setup to squeeze out just a little more startup performance.

Run from Snapshot

If you edit one of your AVD definitions, at the bottom you will see a group titled Emulation Options. Within that group there are two options that improve performance, Snapshot and Use Host GPU. One improves start up performance and the other improves general operating performance. Unfortunately, you can only use one of these improvements at a time. For the sake of our discussion, let's assume we are more concerned with faster start up times, so we will set the option to Snapshot:

  1. Inside Xamarin Studio, go to Tools | Open AVD Manager.

  2. Select the Device Definitions tab.

  3. Select the Nexus 7 by Google image.

  4. Click Create AVD.

  5. Change the AVD Name field.

  6. From the Target drop-down list, select Android 4.4.2 – API Level 19.

  7. From the CPU/ABI drop-down list, select Intel Atom (x86).

  8. In the Emulation Options group, select Snapshot as shown in the following screenshot:

  9. Leave all of the other settings at their default values and click OK.

This new AVD is based on the Intel x86 Atom system image and is set to run from Snapshot. As long as HAXM is running on our system, your initial start up time will still be about the same, but subsequent startups should clock in much faster. On my development machine, start up time still averaged about 25 seconds, but subsequent start up times averaged 5 seconds! Now when your fellow developers tell you that the AVDs running on the packaged SDK are painfully sluggish, you'll know they just haven't applied themselves to finding a solution to the problem.

Third-party AVD options

Do you still feel the need for more speed? No worries, I won't judge. At this stage, if you want to improve performance even further, you need to start looking at alternatives to the SDK Emulator platform. There are several third-party packages that provide comparable and, in some cases, even better performance over the SDK emulators. GenyMotion is one popular alternative that is currently available for free to individual developers and small companies. GenyMotion provides an alternative to the entire emulator paradigm, replacing emulation with virtualization. I personally use the GenyMotion Free edition and I have been very pleased with its performance.

Note

GenyMotion, as well as any other alternative to AVD emulation, is not essential software for working in Xamarin Studio. Therefore, installing and setting up the software is beyond the scope of this book. However, if you are interested in trying out GenyMotion, you can download and try out the free version at https://shop.genymotion.com/index.php? controller=order-opc.

Setting up test devices


Simulators and AVDs are acceptable for development testing, but it is unwise to rely solely on these virtual environments. Therefore, it is important to test on at least one physical device that matches your target environment.

Setting up iOS devices

Although setting up the iOS simulator is a joy, setting up devices for testing is anything but a joy. To test using your iOS device, you must have several items in place. If you have been following along up until now, you already have your Apple iOS Developer Program account. Now, you need a development certificate and a provisioning profile for your device.

Note

If you do not intend to develop iOS applications, you may skip this walkthrough for now and come back to it whenever you're ready.

Obtaining a development certificate

There are two ways to generate your development certificate, and the method you choose is largely based on whether you are developing on a Mac or on a Windows machine. First, for those who are developing on a Mac, we'll look at how to generate your development certificate and associate it with your application within Xamarin Studio. Here are the steps you need to follow:

  1. Open your solution inside Xamarin Studio.

  2. Go to Xamarin Studio | Preferences.

  3. Under the Environment group, select the Developer Accounts panel.

  4. Click the plus (+) button.

  5. Enter your Apple ID and password in the dialog that appears.

  6. Your credentials will be verified and Xamarin will automatically generate the developer certificate for that account.

  7. Close the Preferences dialog.

  8. Double-click on the start-up project, which will open the Project Options dialog.

  9. In the Build group, choose the iOS Application item.

  10. Open the Team drop-down list and choose your developer account.

  11. Click OK.

For those developing iOS applications on a Windows machine, the process is only slightly more involved and requires manual generation of the developer certificate. The steps are follows:

  1. On your Mac, open Finder.

  2. Open Keychain Access by navigating to Applications | Utilities.

  3. Open Keychain Access | Certificate Assistant | Request a Certificate From a Certificate Authority.

  4. Enter your e-mail address and name.

  5. Under the Request group, choose Saved to disk.

  6. Click the Continue button.

  7. When prompted, save the file on your desktop.

  8. Open a browser and log in to the Certificates, Identifiers, and Profiles section of the Developer Portal at https://developer.apple.com/account/overview.action.

  9. In the Certificates section, choose the iOS Apps column.

  10. Click the plus (+) button to create a new certificate.

  11. For the type of certificate, choose iOS App Development.

  12. Click Continue.

  13. On the Generate your certificate screen, upload the certificate file you saved previously.

  14. Click Generate.

  15. Download your new certificate.

  16. Open the file. This will add the certificate to Keychain.

Provisioning your devices

Now that you have a developer certificate for your applications to link to, you still need to add your devices to your developer account by a process called provisioning. To provision a device, we must first create a provisioning profile containing that device's information. You must repeat the following process for every device you want to provision. Here are the steps you need to follow:

  1. Plug your device into your Mac and launch iTunes.

  2. From the sidebar select your device.

  3. Click on the Serial Number value.

  4. The serial number will change to Identifier (UDID).

  5. Copy the serial number value.

  6. Open a browser and log in to the Certificates, Identifiers, and Profiles section of the Developer Portal at https://developer.apple.com/account/overview.action.

  7. Open the Devices section and click the plus (+) button.

  8. Enter a name for your device and the UDID you copied from iTunes.

  9. Click Continue.

  10. Verify that your new information is included in the list of devices and that it is correct.

  11. Click Submit.

  12. Once the profile is generated, click Download.

  13. Open iTunes again and select your device.

  14. Drag the provisioning profile file to the Library in iTunes.

  15. Click the Sync button, and the profile will be installed to your device.

Setting up Android devices

In order to test on an Android device, three steps must be performed:

  1. First, you must enable debugging on the device.

  2. Next, you may need to install additional USB drivers.

  3. Finally, you need to connect your device to your computer using a USB or alternately via Wi-Fi.

Note

If you do not intend to develop Android applications, you may skip this walkthrough for now and come back to it whenever you're ready.

Enabling debugging on your device

To enable debugging on Android 3.2 and older devices, perform the following steps:

  1. On your device, open the Application menu.

  2. Go to Settings.

  3. Select Applications.

  4. Select the Development item.

  5. Check USB Debugging.

To enable debugging on Android 4.0 to 4.1, perform the following steps:

  1. On your device, go to the Settings screen.

  2. Select Developer Options.

  3. Uncheck the USB Debugging option.

To enable debugging on Android 4.2 and higher, perform the following steps:

  1. On your device, go to the Settings screen.

  2. Open the About Phone group.

  3. Tap the Build Number item seven times (yes, I'm serious).

  4. Go back to the Settings screen.

  5. Select Applications.

  6. Select the Development item.

  7. Check USB Debugging.

Installing USB drivers and connecting your device

Using a USB cable is the easiest method of connecting your device and development machine. If you are developing on a Mac, you just need to plug it in. If you are developing on a Windows machine, you may also need to install additional USB drivers for your specific device. Since each manufacturer tends to release their own unique USB drivers, you will need to search over the Internet for the specific instructions for your device.

Under certain circumstances, however, you may want to use Wi-Fi to connect to your device. Connecting via Wi-Fi is completely optional so you may skip this section if it doesn't apply to you. Perform the following steps:

  1. Ensure that your device is connected to the same Wi-Fi network as your development machine.

  2. On your device, go to Settings | Wi-Fi.

  3. Tap the Wi-Fi network you are currently connected to.

  4. Scroll down until you see your device's IP address.

  5. Connect your device to your development machine with a USB cable.

  6. Open Terminal (command prompt on Windows) and enter the following command:

    adb tcpip 5555
    
  7. Disconnect your device from the development machine.

  8. Again in Terminal (command prompt on Windows), enter the following command replacing the listed IP address with that of your device:

    adb connect 192.168.254.12:5555
    
  9. Your device can now be tested across a Wi-Fi network. When you are done testing via Wi-Fi, open Terminal (command prompt on Windows) and enter the following command:

    abd disconnect 192.168.254.12:5555
    

Setting up source control


Xamarin Studio comes equipped with integrated source control, including support for both subversion and Git-based repositories. Even if you don't intend to use the integrated source control features of Xamarin Studio, I still recommend that you set it up so your Solution Explorer can reflect the current version control state of the files in your project.

Whether you are using subversion or Git, if you are running on a Windows machine, you will need to install the respective plugin. Also, each option requires access to an outside repository. Refer to your source control provider's documentation for instructions on setting up an account and installing any required plugins.

Once your development machine is ready to support your choice of source control, the process of setting it up in Xamarin Studio differs only slightly between subversion and Git. Since I use Git for all of my projects, I will demonstrate setting up a Git repo within Xamarin Studio by using the following steps:

  1. Within Xamarin Studio, go to Version Control | Checkout.

  2. Select the Connect to Repository tab.

  3. From the Type drop-down list, choose Git.

  4. In the Url field, enter the URL to your repository.

  5. If the repository you have chosen is a valid Git repo, all of the remaining fields will populate automatically. Otherwise, complete the remaining fields as required.

  6. At the bottom of the form, choose a target directory for your local working copy.

  7. When you are done, your dialog box should resemble the following screenshot:

  8. Click OK.

  9. Enter your repo credentials when prompted.

  10. After your repository finishes downloading, you can close the dialog box.

Tip

Although I use BitBucket for my projects, there are other excellent Git providers available including GitHub, CodeBase, and many more. Be sure to research what each provider offers in the way of services and cost before making your decision, though. Once you select a source control provider you'll find that your choice becomes embedded in the life of your project, and changing it is not a simple matter.

Additional resources for cross-platform developers


As you work with Xamarin Studio, you will undoubtedly have questions about the software and cross-platform development in general. However, you are equally likely to find unique shortcuts and efficiency hacks that others haven't thought of. Therefore, I strongly recommend that you begin to familiarize yourself with the various documentation repositories, forums, and blogs that relate to the technology you are going to be working with so you can give and take with the community.

Xamarin resources

Xamarin Developer Center is your launching point to documentation, code examples, and training videos provided by the Xamarin team (http://docs.xamarin.com).

Xamarin Forums are an excellent place to start. You can sign up using the same login you used to download Xamarin Studio. Take time on a regular basis to read through the posts. You will be amazed by the development gems you will pick up, even from casually reviewing the topics (http://forums.xamarin.com).

Xamarin's Bugzilla server is an important site to become familiar with. If you find bugs in the software, this site will help you inform the community. Likewise, you can research a bug to see if someone else has already posted it; if so, see whether a workaround exists until a fix can be pushed out (https://bugzilla.xamarin.com).

Third-party resources

In addition to the Apple Developer Program, you should familiarize yourself with the Apple Developer Library, which contains documentation on developing all things on Apple (https://developer.apple.com/library/).

The iTunes University offers many resources on iOS and mobile development completely free of charge (https://www.apple.com/apps/itunes-u/).

Android Developer Library contains a wealth of information on mobile development. If you are new to Android development, take the time to review the App Fundamentals tutorial at https://developer.android.com/guide/index.html.

GenyMotion provides some of the fastest Android emulators for app testing and presentation (http://www.genymotion.com/).

Summary


In this chapter, we evaluated the prices and options offered by Xamarin Studio and we walked through installing Xamarin Studio and the secondary software needed for cross-platform development. Next, we learned how to enroll in the various developer programs available to cross-platform developers. Finally, we discussed how to set up the basic functions of our development environment, including how to set up simulators and emulators for development testing and integrating source control.

In Chapter 2, Learning and Customizing the XS Environment, you will create your first iOS and Android applications. Building and customizing those applications will serve as a context to examine the Xamarin Studio environment in more detail.

Left arrow icon Right arrow icon

Key benefits

What you will learn

Integrate Visual Studio, Xcode, and the Android SDK into your development environment Get to grips with all the new Xamarin Studio enhancements from Xamarin 3 Network your Windows box to a Mac build machine for iOS testing and deployment from a PC Install and customize your development environment to suit your workflow Set up Apple and Google developer accounts, and create provisioning profiles for your physical iOS devices Install iOS simulators, create Android device definitions, and link to your physical devices Test and debug your applications using NUnitLite, Instruments, simulators, emulators, and physical devices, all from within Xamarin Studio Deploy your creations to the appropriate app store

Product Details

Country selected

Publication date : Aug 20, 2014
Length 248 pages
Edition : 1st Edition
Language : English
ISBN-13 : 9781783550814
Vendor :
Microsoft
Category :

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
Buy Now

Product Details


Publication date : Aug 20, 2014
Length 248 pages
Edition : 1st Edition
Language : English
ISBN-13 : 9781783550814
Vendor :
Microsoft
Category :

Table of Contents

16 Chapters
Learning Xamarin Studio Chevron down icon Chevron up icon
Credits Chevron down icon Chevron up icon
About the Author Chevron down icon Chevron up icon
About the Reviewers Chevron down icon Chevron up icon
www.PacktPub.com Chevron down icon Chevron up icon
Preface Chevron down icon Chevron up icon
1. Installing and Setting Up Xamarin Studio Chevron down icon Chevron up icon
2. Learning and Customizing the XS Environment Chevron down icon Chevron up icon
3. Working with Xcode and the Android SDK Chevron down icon Chevron up icon
4. Plugins, Templates, Libraries, and Files Chevron down icon Chevron up icon
5. Working with Xamarin.Forms Chevron down icon Chevron up icon
6. Application Lifecycle Chevron down icon Chevron up icon
7. Testing and Debugging Chevron down icon Chevron up icon
8. Deployment Chevron down icon Chevron up icon
Images and Graphics Tables Chevron down icon Chevron up icon
Index Chevron down icon Chevron up icon

Customer reviews

Top Reviews
Rating distribution
Empty star icon Empty star icon Empty star icon Empty star icon Empty star icon 0
(0 Ratings)
5 star 0%
4 star 0%
3 star 0%
2 star 0%
1 star 0%
Filter icon Filter
Top Reviews

Filter reviews by


No reviews found
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

How do I buy and download an eBook? Chevron down icon Chevron up icon

Where there is an eBook version of a title available, you can buy it from the book details for that title. Add either the standalone eBook or the eBook and print book bundle to your shopping cart. Your eBook will show in your cart as a product on its own. After completing checkout and payment in the normal way, you will receive your receipt on the screen containing a link to a personalised PDF download file. This link will remain active for 30 days. You can download backup copies of the file by logging in to your account at any time.

If you already have Adobe reader installed, then clicking on the link will download and open the PDF file directly. If you don't, then save the PDF file on your machine and download the Reader to view it.

Please Note: Packt eBooks are non-returnable and non-refundable.

Packt eBook and Licensing When you buy an eBook from Packt Publishing, completing your purchase means you accept the terms of our licence agreement. Please read the full text of the agreement. In it we have tried to balance the need for the ebook to be usable for you the reader with our needs to protect the rights of us as Publishers and of our authors. In summary, the agreement says:

  • You may make copies of your eBook for your own use onto any machine
  • You may not pass copies of the eBook on to anyone else
How can I make a purchase on your website? Chevron down icon Chevron up icon

If you want to purchase a video course, eBook or Bundle (Print+eBook) please follow below steps:

  1. Register on our website using your email address and the password.
  2. Search for the title by name or ISBN using the search option.
  3. Select the title you want to purchase.
  4. Choose the format you wish to purchase the title in; if you order the Print Book, you get a free eBook copy of the same title. 
  5. Proceed with the checkout process (payment to be made using Credit Card, Debit Cart, or PayPal)
Where can I access support around an eBook? Chevron down icon Chevron up icon
  • If you experience a problem with using or installing Adobe Reader, the contact Adobe directly.
  • To view the errata for the book, see www.packtpub.com/support and view the pages for the title you have.
  • To view your account details or to download a new copy of the book go to www.packtpub.com/account
  • To contact us directly if a problem is not resolved, use www.packtpub.com/contact-us
What eBook formats do Packt support? Chevron down icon Chevron up icon

Our eBooks are currently available in a variety of formats such as PDF and ePubs. In the future, this may well change with trends and development in technology, but please note that our PDFs are not Adobe eBook Reader format, which has greater restrictions on security.

You will need to use Adobe Reader v9 or later in order to read Packt's PDF eBooks.

What are the benefits of eBooks? Chevron down icon Chevron up icon
  • You can get the information you need immediately
  • You can easily take them with you on a laptop
  • You can download them an unlimited number of times
  • You can print them out
  • They are copy-paste enabled
  • They are searchable
  • There is no password protection
  • They are lower price than print
  • They save resources and space
What is an eBook? Chevron down icon Chevron up icon

Packt eBooks are a complete electronic version of the print edition, available in PDF and ePub formats. Every piece of content down to the page numbering is the same. Because we save the costs of printing and shipping the book to you, we are able to offer eBooks at a lower cost than print editions.

When you have purchased an eBook, simply login to your account and click on the link in Your Download Area. We recommend you saving the file to your hard drive before opening it.

For optimal viewing of our eBooks, we recommend you download and install the free Adobe Reader version 9.