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.
This changes the source code entry point and lifecycle of apps.
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.
Copy the
simple_gl_app
template from the C-API sample directory and rename it toarworld_app
.Adjust the following files in your new project. In
app/build.gradle
change:
+ applicationId = ‘com.company.arworld’
- applicationId = ‘com.magicleap.simple_gl_app’
- 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"
- In
app/src/main/res/values/strings.xml
change
+ <string name="app_name" >AR World</string>
- <string name="app_name" >simple_gl_app</string>
- In
app/src/main/cpp/src/CMakeLists.txt
change any occurrence of “simple_gl_app” with “arworld_app”. - Adjust the target_link_libraries to match your use of shared libraries.
- Add all the source code files you need to compile to “add_library”
- 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.
Change the code entry point changes:
int main(int argc, char * argv[])
becomesvoid android_main(struct android_app *state)
Any references to
ml_lifecycle
likeMLLifecycleInit
have been removed in favor of the Android lifecycle handling. In a native_app_glue project this is handled through theandroid_app * state
and the event mechanism therein. See thesimple_gl_app
on how to do this.Any references to
ML_LOG
should be replaced withandroid 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.
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 1 | Magic Leap 2 |
---|---|
libml_audio.so | libaudio.magicleap.so |
libml_bluetooth_adapter.so | libbluetooth_adapter.magicleap.so |
libml_bluetooth_gatt.so | libbluetooth_gatt.magicleap.so |
libml_bluetooth_le.so | libbluetooth_le.magicleap.so |
libml_camera.so | libcamera.magicleap.so |
libml_camera_metadata.so | libcamera_metadata.magicleap.so |
libml_graphics.so | libgraphics.magicleap.so |
libml_graphics_utils.so | libgraphics_utils.magicleap.so |
libml_input.so | libinput.magicleap.so |
libml_media_ccparser.so | libmedia_ccparser.magicleap.so |
libml_media_cea708parser.so | libmedia_cea708parser. magicleap.so |
libml_media_codeclist.so | libmedia_codeclist.magicleap.so |
libml_media_codec.so | libmedia_codec.magicleap.so |
libml_media_crypto.so | libmedia_crypto.magicleap.so |
libml_media_drm.so | libmedia_drm.magicleap.so |
libml_media_error.so | libmedia_error.magicleap.so |
libml_media_extractor.so | libmedia_extractor.magicleap.so |
libml_media_format.so | libmedia_format.magicleap.so |
libml_media_muxer.so | libmedia_muxer.magicleap.so |
libml_media_player.so | libmedia_player.magicleap.so |
libml_media_recorder.so | libmedia_recorder.magicleap.so |
libml_perception.so | libperception.magicleap.so |
libml_platform.so | libplatform.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
).
- ml_app_connect.h
- ml_connections.h
- ml_contacts.h
- ml_screens.h
- ml_found_object.h
- ml_persistent_coordinate_frames.h
- ml_passable_world.h
- ml_data_array.h
- ml_avatar.h
- ml_dispatch.h
- ml_lifecycle.h
- ml_logging.h
- ml_keycodes.h
- ml_app_analytics.h
- ml_identifier.h
- ml_identity.h
- ml_cloud.h
- ml_secure_storage.h
- ml_sharedfile.h
- ml_fileinfo.h
- ml_locale.h
- ml_privilege_functions.h
- ml_privileges.h
- ml_purchase.h
- ml_networking.h
- ml_token_agent.h
- ml_invoke_async.h
- ml_location.h
- ml_imu_tracking.h