Cross Platform
Android
iOS
Mac

Compiling for Different Devices

You can configure how your executable is built from the Xamarin Studio's iPhone Build properties page. Some features are configured on the default page, some on the Advanced page (available on newer versions of Xamarin Studio and Xamarin.iOS). In addition to the configuration options available on the UI, you can also pass your own set of command line options to the Xamarin.iOS build tool (mtouch).

SDK Options

Xamarin Studio lets user configure two important properties: the iPhoneOS SDK to use to build your software and the minimum required OS version.

The iPhoneOS SDK version option lets you use different versions of an Apple published SDK, this directs Xamarin.iOS to which compilers, linkers and libraries it should reference during your build.

The Minimum OS version setting is used to select the minimum required version of the operating system on which your application will run. This is turned into a property in your Info.plist file. You should pick the minimum version that has all the APIs that you need to run your application.

In general, the Xamarin.iOS API exposes all the methods available in the latest version of the SDK, and when necessary, we provide convenience properties that allow you to detect if the functionality is available at runtime (for example, UIDevice.UserInterfaceIdiom and UIDevice.IsMultitaskingSupported always work on Xamarin.iOS, we do all the work behind the scenes).

Linking

See our dedicated page on the Linker to learn more about how the linker helps you reduce the size of your executables and to find out how to use it effectively.

Code Generation Engine

Starting with Xamarin.iOS 4.0, there are two code generation backends to Xamarin.iOS. The regular Mono code generation engine and one based on the LLVM Optimizing Compiler. Each engine has its pros and cons.

Typically, during the development process, you will likely use the Mono code generation engine as it will let you iterate quickly. For release builds and AppStore deployment, you will want to switch to the LLVM code generation engine.

Code Generation Features
  Compilation Speed ARMV6

(not supported)
ARMv7

(iPhone 3GS and newer)
ARMv7s

(iPhone 5)
Traditional Engine Fast Yes No No
LLVM Engine Slow Yes Yes Yes

 

The LLVM optimizing backend engine produces both faster and tighter code than the Mono engine does, at the cost of long compile times.

You can enable these from the Advanced Tab in your iOS Build panel in Xamarin Studio or Visual Studio.

ARMV7 and ARMV7s support

Both the original iPhone and the iPhone 3G used an ARMv6 CPU. Newer models of the iPhone, starting with the 3GS and including the iPhone 4 and the iPads come with a more sophisticated processor, the ARMv7. iPhone 5 ships with the ARMv7s processor.

If you target only the ARMv7s processor, the code generated will be slightly faster, but it will no longer run on ARMv7 or ARMv6 systems unless you compile a fat binary that contains multiple executables in your package.

Apple does not allow developers to upload ARMv7s or ARMv7-only executables for a product that originally ran on the ARMv6.

ARMv6 is not longer supported in XCode as of XCode 4.5. If you want to target ARMv6 in Xamarin Studio, you must have an earlier version of XCode installed.

ARM Thumb Support

Thumb is a more compact instruction set used by ARM processors. By enabling the Thumb support, you can reduce the size of your executable, at the expense of slower execution times. Thumb is supported on ARMv6, ARMv7 and ARMv7s.

Conditional Framework Useage

If your project wants to leverage some of the features in the newer iOS releases, you may need to conditionally rely on certain new frameworks. A prime example of this is wanting to use iAd when running on iOS 4.0 or greater, but still support 3.x devices. To accomplish this you need to let Xamarin.iOS know that you need to link against the iAd framework "weakly". Weak bindings ensure that the framework is only loaded on demand the first time a class from the framework is required.

To do this you should take the following steps:

  • Open your Project Options and navigate to the iOS Build pane.
  • Add '-gcc_flags "-weak_framework iAd"' to the Additional Options for each configuration you wish to weakly link on

In addition to this you will need to guard your usage of the types from running on older versions of iOS where they may not exist. There are several methods to accomplish this, but one of which is parsing UIDevice.CurrentDevice.SystemVersion.