Exercise - Build Azure spatial anchors for Android and iOS

Completed

In this unit, you'll learn how to build your project to Android and iOS devices by using AR Foundation, ARCore XR Plugin, and ARKit XR Plugin.

Install in-built Unity packages

Upgrade or install one of the following inbuilt packages from Unity Package Manager:

  • ARCore XR Plugin 4.0.12 if you're developing for Android
  • ARKit XR Plugin 4.0.12 if you're developing for iOS

Caution

Not all package versions are compatible with the MRTK, and only certain versions work together. Be sure to install the exact version shown in the list.

For instructions on how to upgrade and install inbuilt packages, see the Unity documentation.

Configure the MRTK for an AR Foundation camera

In this section, you'll configure the MRTK to deploy to a mobile device.

  1. On the Hierarchy pane, select the MixedRealityToolkit object. On the Inspector pane, select the Camera tab, clone the camera profile, and give it a suitable name like AzureSpatialAnchors_ARCameraProfile.

    Screenshot of configuring the Mixed Reality Toolkit for an augmented reality camera.

    Tip

    For information on how to clone MRTK profiles, see Configuring the Mixed Reality Toolkit profiles.

  2. With the Camera tab still selected on the Inspector pane, expand Camera Settings Providers. Select the minus sign (-) to remove Windows Mixed Reality Camera Settings or XR SDK Windows Mixed Reality Camera Settings.

    Screenshot of camera settings.

  3. Select the + Add Camera Settings Provider button, and then expand the newly added data provider.

    Screenshot of adding a camera settings provider.

  4. In the Type dropdown list, change the type to Microsoft.MixedReality.Toolkit.Experimental.UnityAR > UnityARCameraSettings.

    Screenshot of changing the type of the added camera settings provider.

  5. Update the MRTK UnityAR script definitions by selecting Mixed Reality > Toolkit > Utilities > UnityAR > Update Scripting Defines.

Build your application to your Android device

In this section, you'll configure your project to build and deploy it to an Android device.

  1. On the Unity menu, select File > Build Settings to open the Build Settings dialog. Switch the platform to Android.

    Screenshot of changing build settings.

    Tip

    For information on how to switch the build platform, see Switching the build platform in the Unity documentation.

    Close the Build Settings dialog.

  2. On the Unity menu, select Mixed Reality > Toolkit > Utilities > Configure Project for MRTK to open the MRTK Project Configurator dialog. Ensure that all options are selected, and then select the Apply button to apply the settings.

    Screenshot of the project configurator dialog for the Mixed Reality Toolkit.

  3. On the Unity menu, select Edit > Project Settings to open the Project Settings dialog. Then locate the Player > Other Settings section, select Vulkan, and remove it by selecting the minus sign (-).

    Screenshot of project settings.

    On the Unity menu, select Edit > Project Settings > XR Plug-in Management, and then select the ARCore checkbox.

    Screenshot of the ARCore checkbox in the list of plug-in providers.

    Close the Project Settings dialog and open the Build Settings dialog again.

  4. In the Build Settings dialog, select the Add Open Scenes button to add your current scene to the Scenes In Build list. Use a USB cable to connect your Android device to your computer, and the select the device from the Run Device dropdown list.

    Screenshot of the Run Device dropdown list.

    Note

    If your device doesn't appear in the Run Device dropdown list, you might need to select the Refresh button next to the box.

  5. In the Build Settings dialog, select the Build And Run button to open the Build Android dialog.

  6. Choose a suitable location to store your build—for example, D:\MixedRealityLearning\Builds. Give the .apk file a suitable name—for example, MRTKTutorials-AzureSpatialAnchors. Then select the Save button to start the build process.

    Screenshot of building to Android.

    Note

    If you get an error in the Unity Console Window related to Android SDK, NDK, or JDK modules, open Unity Hub and install the associated Android Build Support modules.

    When the build process is complete, your apps should automatically load on your Android device.

Build your application to your iOS device

In this section, you'll configure your project to build and deploy it to your iOS device.

  1. On the Unity menu, select File > Build Settings to open the Build Settings dialog. Switch the platform to iOS.

    Screenshot of build settings and selecting the operating system.

    Tip

    For information on how to switch the build platform, see Switching the build platform in the Unity documentation.

    Close the Build Settings dialog.

  2. On the Unity menu, select Mixed Reality > Toolkit > Utilities > Configure Project for MRTK to open the MRTK Project Configurator window. Ensure that all options are selected, and then select the Apply button to apply the settings.

    Screenshot of the Mixed Reality Toolkit project configurator.

    On the Unity menu, select Edit > Project Settings > XR Plug-in management. Then select the ARKit checkbox.

    Screenshot of the XR Plug-in Management area of project settings.

  3. On the Unity menu, select Edit > Project Settings to open the Player Settings dialog. Locate the Player > Other Settings section and clear the Strip Engine Code checkbox.

    Screenshot of the Strip Engine Code checkbox.

    Close the Player Settings dialog and open the Build Settings dialog again.

  4. In the Build Settings dialog, select the Add Open Scenes button to add your current scene to the Scenes In Build list.

    Screenshot of scenes in build.

  5. In the Build Settings dialog, select the Build button to open the Build iOS dialog.

  6. Choose a suitable location to store your Xcode project—for example, D:\MixedRealityLearning\Builds. Create a new folder and give it a suitable name—for example, MRTKTutorials-AzureSpatialAnchors. Then select the Select Folder button to start the build process.

    Screenshot of selecting a folder.

    When the build process is complete, follow the Export the Xcode project instructions to deploy your Xcode project to your iOS device.