Book Image

Learning Xamarin studio

By : William Smith
Book Image

Learning Xamarin studio

By: William Smith

Overview of this book

Table of Contents (16 chapters)
Learning Xamarin Studio
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

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.