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.
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