Skip to main content
Version: 14 Oct 2024

Building via Command Line

This section outlines the steps required to build the Magic Leap OpenXR Samples using the build.py script from the command line. Before attempting to build the samples, please complete the environment setup steps in Environment Setup. The build script uses gradle to build each of the applications.

Prerequisites

To build the OpenXR samples, you need the following:

  • Complete Environment Setup.
  • MLSDK SDK Version 1.5.0 or higher.
  • The latest OpenXR Samples from the ML Hub.
caution

The MLSDK must be installed into a path without spaces.

Limitations

Please note the following limitations:

  • You cannot run the OpenXR samples using the Magic Leap Application Simulator.
  • On Windows, long filenames can cause problems while building the OpenXR samples. We recommend installing the samples in a directory with a short path.

Building the Samples

You can either build all of the Magic Leap OpenXR Samples or individual ones. The steps outlined below assume that you wish to build all of the Magic Leap OpenXR samples. However, if you wish to build an individual sample application, append the --project option followed by the project name you wish to build. For example, --project eye_gaze.

  1. After downloading the Magic Leap OpenXR samples from the Magic Leap Hub, navigate to the OpenXR Samples directory.
cd %USERPROFILE%\MagicLeap\mlsdk\<Version>\samples\openxr_samples\samples
  1. Verify that your environment variables are set properly before running the build script. See the Open XR Environment Setup Guide to learn more.
Command Line
echo %ANDROID_HOME%
echo %MLSDK%
echo %JAVA_HOME%
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.

  1. Run the following command to build Debug variants of the OpenXR Samples for the the Magic Leap 2. See the Notes on Building section for more information about build options.
python build.py --build device --config debug

info
  • By default build.py assumes that Visual Studio 2019 version 17 is used. To select a different compiler, Visual Studio 2017 for example, add --msvc “Visual Studio 15 2017” to the command line.
  • Currently, the SDK supports Visual Studio up to version 17, 2019. If you are switching compilers make sure to do a full clean build by using the --clean parameter as shown below:
python build.py --build device --config debug --msvc "Visual Studio 17 2019"

Build Script Parameters

  • All build.py scripts by default build for both device (aka ML2) and host (aka App Sim). If you only wish to build for host add --build host. If you only wish to build for device add --build device.
  • All build.py scripts by default build release config only. If you only wish to build debug config use --config debug. If you wish to build both debug and release configs use --config release debug.
  • Use --project followed by the project name if you wish to build an individual sample. For example, --project eye_gaze.
  • When building apps make sure that the MLSDK environment variable is pointing to the SDK install location.
info

If you receive errors that the Vulkan_LIBRARY is missing, make sure you have the Vulkan SDK installed on your machine.

Building Release APKs

To generate release variants of the sample applications, you will need to sign the APK using a keystore. This is a standard convention for Android based applications. Use the instructions below to learn how to create a keystore that is compatible with the build.py script.

Generating Certificates for Signed Release APKs

For building signed release APKs, you need the following files in your MagicLeap\mlsdk\<VERSION>\samples\openxr_samples\scripts directory:

  • keystore.properties
  • mlsdk.keystore

Your scripts directory won’t have these files, so you will need to create them yourself.

  1. mlsdk.keystore file can be generated using either:
  • keytool command, supplied by Java JDK installation
    • keytool -genkey -v -keystore mlsdk.keystore -alias samples_key -keyalg RSA -keysize 2048 -validity 10000
  • Android Studio in Build > Generate Signed Bundle / APK... > APK > Key store path > Create new...
  1. Using a file editor create an empty keystore.properties file that has the following structure:
storePassword=<mlsdk.keystore password>
keyPassword=<key password>
keyAlias=samples_key
storeFile=<path to mlsdk.keystore>