Skip to main content
Version: 12 Dec 2024

Environment Setup

This guide walks you through setting up your environment for native development on Magic Leap 2. By the end of the guide, you will have everything necessary to build and run the Magic Leap OpenXR samples, allowing you to explore the capabilities of OpenXR on Magic Leap 2 and develop your own AR applications.

MacOS Xcode

If you are using MacOS you may need to install Xcode before proceeding with the instructions below: https://developer.apple.com/xcode/download/.

Install Android Studio

  1. Download and install the latest Electric Eel version of Android Studio. (2022.1.1 Patch 2 at time of writing)

  2. During installation, make sure to include:

    • Android SDK Tools
    • Android SDK Command Line Tools
    • Android SDK Platform Tools

Additional Packages & Tools

After installing Android Studio, you will be able to install the additional packages and tools required to develop applications for Magic Leap 2.

  • Android SDK 10 (Q) API Level 29
  • Android NDK, v 25.0.8775105
  • CMake v 3.22.1

This section provides step-by-step instructions on how to install these packages and tools from Android Studio's Package Manager.

  1. Open the SDK Manager
    • From the Android Studio launch screen select More Actions > SDK Manager.
    • You can also open the SDK manager from inside an existing project by selecting Tools > SDK Manager.
SDK Manager Option in Tools Dropdown
  1. Install Android SDK 10 (Q) API Level 29 under SDK Platforms.
Android SDK option in Android Studio
  1. Install Android NDK version 25.0.8775105 under SDK Tools.
tip

If you don't see different version options, check Show Package Details at the bottom right.

Android NDK option in Android Studio
  1. Install CMake version 3.22.1 under SDK Tools.
CMake Option in Android Studio
Unable to find a build program corresponding to "Ninja"

You may need to download Ninja if CMake cannot locate it automatically. Refer to Ninja's official website for installation instructions.

CMake Error: CMake was unable to find a build program corresponding to "Ninja".

Download Magic Leap SDK

When using Magic Leap specific features that are not available via OpenXR extensions, you will need to download and install the Magic Leap SDK. For example, the samples use MLAudio which is part of the MLSDK.

  1. Open the Magic Leap Hub and select the Packages option in the left sidebar.
  2. From the packages section select ML C SDK.
ML C SDK option highlighted in the Magic Leap Hub.
  1. Click Install and wait for the download to complete.
  2. These file are downloaded into the following directory by default:
 %USERPROFILE%/MagicLeap/mlsdk/<Version>/

Download Vulkan SDK

The Vulkan SDK allows developers to create applications that take advantage of Magic Leap 2's rendering capabilities. While Magic Leap 2 supports Native Applications that use OpenGLES, it is strongly recommended to use Vulkan instead.

  1. Download and install the latest version of the Vulkan SDK.
  2. Once installed, set the VULKAN_SDK and VULKAN_PATH to point at the directory that contains the Vulkan SDK installation.

Set Environment Variables

If you plan to build applications via a command line interface (CLI), you must set the following environment variables. The example below demonstrates how to set the environment variables for a single session. Note, the directories in the examples below may be different for you depending on where you installed the tools.

  • ANDROID_HOME: Points to the top level Android SDK folder.
  • MLSDK: Points to the top level Magic Leap SDK folder.
  • JAVA_HOME: Points to the top level Java Virtual Machine folder.
Command Line
set ANDROID_HOME=%USERPROFILE%\AppData\Local\Android\sdk

set MLSDK=%USERPROFILE%\MagicLeap\mlsdk\<mlsdk_version>

set JAVA_HOME=C:\Program Files\Android\Android Studio\jre
caution

If you are using a command line interface such as Git Bash, you will need to use Unix-like syntax instead of the formatting used in the example above.