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.
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
Download and install the latest Electric Eel version of Android Studio. (2022.1.1 Patch 2 at time of writing)
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.
- 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.
- Install Android SDK 10 (Q) API Level 29 under SDK Platforms.
- Install Android NDK version 25.0.8775105 under SDK Tools.
If you don't see different version options, check Show Package Details at the bottom right.
- Install CMake version 3.22.1 under SDK Tools.
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.
- Open the Magic Leap Hub and select the Packages option in the left sidebar.
- From the packages section select ML C SDK.
- Click Install and wait for the download to complete.
- These file are downloaded into the following directory by default:
- Windows
- MacOS
%USERPROFILE%/MagicLeap/mlsdk/<Version>/
$HOME/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.
- Download and install the latest version of the Vulkan SDK.
- Once installed, set the
VULKAN_SDK
andVULKAN_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.
- Windows
- MacOS
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
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.
export ANDROID_HOME=~/Library/Android/sdk
export MLSDK=~/MagicLeap/mlsdk/<mlsdk_version>
export JAVA_HOME=/Applications/Android\ Studio.app/Contents/jbr/Contents/Home
The JAVA_HOME
value may be different, verify its location by running:
/usr/libexec/java_home