Skip to main content
Version: 12 Dec 2024

Migrating from ML1

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 

Magic Leap 2 API Changes

MLInput

The Magic Leap 2 Controller lacks display LEDs. The following APIs are not supported in Magic Leap 2:

  • MLInputStartControllerFeedbackPatternLED
  • MLInputStartControllerFeedbackPatternEffectLED.
  • ML2 does not support Wacom tablets.
  • MLInput will not support mouse and keyboard events, use NDK APIs for this.

MLPersistentCoordinate Frames

Local PCFs are not supported on Magic Leap 2. They will be replaced by Anchor APIs.

MLCamera Changes

Magic Leap 2 comes with a new camera stack (both hardware and software) and introduces new camera APIs. Magic Leap 1 camera APIs will no longer be supported in Magic Leap 2.

info

Magic Leap 2 developers should use Android's standard Camera NDK APIs to take photos or images.

Library Renaming

AOSP has introduced new naming conventions for public libraries. Library names have changed between Magic Leap 1 and Magic Leap 2.

Magic Leap 1Magic Leap 2
libml_audio.solibaudio.magicleap.so
libml_bluetooth_adapter.solibbluetooth_adapter.magicleap.so
libml_bluetooth_gatt.solibbluetooth_gatt.magicleap.so
libml_bluetooth_le.solibbluetooth_le.magicleap.so
libml_camera.solibcamera.magicleap.so
libml_camera_metadata.solibcamera_metadata.magicleap.so
libml_graphics.solibgraphics.magicleap.so
libml_graphics_utils.solibgraphics_utils.magicleap.so
libml_input.solibinput.magicleap.so
libml_media_ccparser.solibmedia_ccparser.magicleap.so
libml_media_cea708parser.solibmedia_cea708parser. magicleap.so
libml_media_codeclist.solibmedia_codeclist.magicleap.so
libml_media_codec.solibmedia_codec.magicleap.so
libml_media_crypto.solibmedia_crypto.magicleap.so
libml_media_drm.solibmedia_drm.magicleap.so
libml_media_error.solibmedia_error.magicleap.so
libml_media_extractor.solibmedia_extractor.magicleap.so
libml_media_format.solibmedia_format.magicleap.so
libml_media_muxer.solibmedia_muxer.magicleap.so
libml_media_player.solibmedia_player.magicleap.so
libml_media_recorder.solibmedia_recorder.magicleap.so
libml_perception.solibperception.magicleap.so
libml_platform.solibplatform.magicleap.so

Removed Features

The following features are scheduled for removal with Magic Leap 2 launch. Some of them will be replaced by Android APIs (e.g. ml_imu_tracking.h), some will be replaced within the Magic Leap APIs (e.g. ml_persistent_coordinate_frames.h will be replaced by the anchors APIs), and some will be removed completely (e.g. ml_purchase.h).

  1. ml_app_connect.h
  2. ml_connections.h
  3. ml_contacts.h
  4. ml_screens.h
  5. ml_found_object.h
  6. ml_persistent_coordinate_frames.h
  7. ml_passable_world.h
  8. ml_data_array.h
  9. ml_avatar.h
  10. ml_dispatch.h
  11. ml_lifecycle.h
  12. ml_logging.h
  13. ml_keycodes.h
  14. ml_app_analytics.h
  15. ml_identifier.h
  16. ml_identity.h
  17. ml_cloud.h
  18. ml_secure_storage.h
  19. ml_sharedfile.h
  20. ml_fileinfo.h
  21. ml_locale.h
  22. ml_privilege_functions.h
  23. ml_privileges.h
  24. ml_purchase.h
  25. ml_networking.h
  26. ml_token_agent.h
  27. ml_invoke_async.h
  28. ml_location.h
  29. ml_imu_tracking.h