Developing a ML2 app with Java code

Give us as much detail as possible regarding the issue you're experiencing.

ML2 OS version: B3E.220619.07-R.107
MLSDK version: SDK Version 29
Host OS: (Windows/MacOS) Windows 10

I would like to deploy on the ML2 an application mainly written in Java. I see that, in the samples, the AndroidManifest.xml has an entry hasCode that is set to true if the .apk has Java code, so I would assume what I am trying to do is possible.

The Java application consists of a running on a GUI designed through an activity_main.xml file (standard android project structure). The project still uses gradle to build the apk. I tried the application on an android simulator and it works fine. I modified the gradle settings and the project settings to be able to build the app in the ML2, and although it is installed correctly on the device, when I run it I just see a black screen.

Hence, to find a workaround, I would now clone a ML2 sample and import the necessary java files, but I am wondering what I should do to have the java application build, since the samples are set up to compile c++ code. Basically, I would like to know what I need to write on the .cpp side to be able to compile a and possible changes to the gradle files/project settings from the samples to support Java code, besides setting hasCode to true. I could not find any sample with Java code integrated.

Any help would be greatly appreciated.

Marco Beccarini

1 Like

Typical Android apps can run in 2D mode on ML2, it will be rendered in place of home menu.

If you want AR immersive app you need to add

<meta-data android:name="com.magicleap.augmented_reality_only" android:value="true" />

tag in the app manifest (see capi sampe apps for reference) and you must use ml_graphics api (capi).

essentially you need a mix of java and c/c++ talking via jni.

check simple_gl_app in native samples, the app uses android native app glue (no java). but you can essentially do something similar - have lifecycle events handled in java and call into native code to invoke ml apis.

1 Like