Exercise - Build Azure spatial anchors for Android and iOS
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.
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.
Tip
For information on how to clone MRTK profiles, see Configuring the Mixed Reality Toolkit profiles.
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.
Select the + Add Camera Settings Provider button, and then expand the newly added data provider.
In the Type dropdown list, change the type to Microsoft.MixedReality.Toolkit.Experimental.UnityAR > UnityARCameraSettings.
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.
On the Unity menu, select File > Build Settings to open the Build Settings dialog. Switch the platform to Android.
Tip
For information on how to switch the build platform, see Switching the build platform in the Unity documentation.
Close the Build Settings dialog.
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.
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 (-).
On the Unity menu, select Edit > Project Settings > XR Plug-in Management, and then select the ARCore checkbox.
Close the Project Settings dialog and open the Build Settings dialog again.
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.
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.
In the Build Settings dialog, select the Build And Run button to open the Build Android dialog.
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.
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.
On the Unity menu, select File > Build Settings to open the Build Settings dialog. Switch the platform to iOS.
Tip
For information on how to switch the build platform, see Switching the build platform in the Unity documentation.
Close the Build Settings dialog.
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.
On the Unity menu, select Edit > Project Settings > XR Plug-in management. Then select the ARKit checkbox.
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.
Close the Player Settings dialog and open the Build Settings dialog again.
In the Build Settings dialog, select the Add Open Scenes button to add your current scene to the Scenes In Build list.
In the Build Settings dialog, select the Build button to open the Build iOS dialog.
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.
When the build process is complete, follow the Export the Xcode project instructions to deploy your Xcode project to your iOS device.
Trebate pomoć? Pogledajte naš vodič za rješavanje problema ili pošaljite željene povratne informacije prijavljivanjem problema.