Skip to main content
Version: 31 Aug 2023

Magic Leap 1 Migration Guide

The Magic Leap 2 no longer uses mabu as the build system. Instead, Gradle and CMake are now the tools used to build apps when using the Magic Leap C-API.

info

This changes the source code entry point and lifecycle of apps.

tip

For more information on C-API feature differences between Magic Leap 1 and 2, reference the C-API Changes page.

Example

Let’s convert the following application:

Name: “AR World”
Id: “com.arcompany.arworld”

Magic Leap 2 project using a sample file

First we will set up an Magic Leap 2 project using a sample file.

  1. Copy the simple_gl_app template from the C-API sample directory and rename it to arworld_app.

  2. Adjust the following files in your new project. In app/build.gradle change:

+ applicationId = ‘com.company.arworld’
- applicationId = ‘com.magicleap.simple_gl_app’
  1. In AndroidManifest.xml change:
+ <meta-data android:name=”android.app.lib_name”android:value=”arworld_app”/>
- <meta-data android:name=“android.app.lib_name”android:value = “simple_gl_app”/>
...
+ package="com.arcompany.arworld
- package="com.magicleap.capi.simple_gl_app"
  1. In app/src/main/res/values/strings.xml change
+ <string name="app_name" >AR World</string>
- <string name="app_name" >simple_gl_app</string>
  1. In app/src/main/cpp/src/CMakeLists.txt change any occurrence of “simple_gl_app” with “arworld_app”.
  2. Adjust the target_link_libraries to match your use of shared libraries.
  3. Add all the source code files you need to compile to “add_library”
  4. Copy all your source code files to app/src/main/cpp.

Convert source code to match Magic Leap 2 API

Now that the files are in place, we will modify the source code to match the new Magic Leap 2 API.

  1. Change the code entry point changes: int main(int argc, char * argv[]) becomes void android_main(struct android_app *state)

  2. Any references to ml_lifecycle like MLLifecycleInit have been removed in favor of the Android lifecycle handling. In a native_app_glue project this is handled through the android_app * state and the event mechanism therein. See the simple_gl_app on how to do this.

  3. Any references to ML_LOG should be replaced with android logging.

Privileges have been replaced with Permissions (exact conversion t.b.d.)

After connecting the headset to your machine, you can either use Android Studio or the command line to build and run your app on the device.

Android Studio

Open the project in Android Studio and build and run the project. (Run > Run App or Run > Debug App)

Command Line

Run the following set of commands to build, install, and run the application:

./gradlew build

adb install app/build/outputs/apk/ml2/debug/com.arcompany.arworld-debug.apk

adb shell am start -a android.intent.action.MAIN -n com.arcompany.arworld/android.app.NativeActivity

To uninstall the application run the following command:

adb uninstall com.magicleap.capi.sample.lifecycle