Skip to main content
Version: 14 Oct 2024

Building via Android Studio

Overview

This section outlines the steps required to build the Magic Leap OpenXR Samples using Android Studio.

Prerequisites

To build the OpenXR samples, you need the following:

  • Complete Environment Setup.
  • MLSDK Version 1.5.0 or higher.
  • The latest OpenXR Samples from the Magic Leap Hub (ML Hub).
caution

The MLSDK must be installed into a path without spaces.

The instructions below assume that all the content has been extracted to the %USERPROFILE% directory.

Setup

  1. Open the Android Studio SDK Manager by going to Tools > SDK Manager.

  2. Under the SDK Update Sites tab, create a new entry pointing at ml-addon.xml by inserting https://thelab.magicleap.cloud/packages_mlhub/artifacts/ml-addon.xml in the URL field.

SDK Update Sites XML Link Entry
  1. Under the SDK Tools tab, select and install both the Magic Leap SDK (Tools) and the Magic Leap SDK.
MLSDK options at the bottom of the SDK Tools tab
tip

If you are having issues with the steps above taking effect, restart Android Studio.

Build and Run Sample Application

  1. Open Android Studio then select Open.
  2. Choose the a sample project, located in the %USERPROFILE%\MagicLeap\tools\unity\<Version>\samples\openxr_samples\samples.
  3. If prompted, select Trust Project.
  4. Wait until the project is initialized.
  5. Make sure your Magic Leap device is connected and ensure that Magic Leap 2 is set as the target device.
  6. Click the Run button to build the project and start the app on your Magic Leap device.

Building Signed Release APKs in Android Studio

You can build both signed releases and debug APKs following these steps:

  1. Go to Build > Generate Signed Bundle / APK....
  2. Choose APK.
  3. (Optional) If you do not have a certificate, generate a new one using Key store path > Create new....
  4. Fill out fields with data from the certificate and click Next.
  5. Choose the build variants that you want to build (“ml2Release”, “ml2Debug”, or both).
  6. Click Finish to build.

Generating Certificates for Signed Release APKs

For building signed release APKs, you need the following files in your scripts/ directory:

  • keystore.properties
  • mlsdk.keystore

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

  1. mlsdk.keystore file can be generated using either:
  • keytool command, supplied by Java JDK installation
  • Android Studio in Build > Generate Signed Bundle / APK... > APK > Key store path > Create new...
  1. keystore.properties has the following structure:
storePassword=<mlsdk.keystore password>
keyPassword=<key password>
keyAlias=<key alias>
storeFile=<path to mlsdk.keystore>
note

The <path to mlsdk.keystore> will be appended to the parent directory of samples/ directories like so: /home/user/Downloads/sdk_native_samples_src/<path to mlsdk.keystore>

Installing and Launching Apps via Command Line

adb install <path_to_apk>
adb shell am start -a android.intent.action.MAIN -n <app_package_name>/android.app.NativeActivity

To uninstall use this command:

adb uninstall <app_package_name>

For more ADB commands, reference the ADB Commands Guide.