Android Support in the jMonkeyEngine

This is a draft of a feature that is work in progress. If you have questions or suggestions, please leave a comment on the !

Requirements

Features

JMonkeyEngine3 Android Integration

jMonkeyPlatform Android Integration

Mobile deployment is a "one-click" option next to Desktop/WebStart/Applet deployment in the jMonkeyPlatform.

Beta Instructions

  1. Make sure you have installed the Android Project Support into the jMonkeyPlatform.
  2. Open the jMonkeyPlatform Options>Mobile and enter the path to your Android SDK directory, and click OK. E.g. /opt/android-sdk

Activate Android Deployment

  1. Open an existing JME3 project, or create a new JME3 project.
  2. Right-click the project node in the Projects Window and open the Properties.
  3. In the Application>Mobile Properties, enable Mobile Deployment, and select an Android target.
    This creates a "mobile" folder in your projects directory. This folder contains a complete android project with correct settings to run the application using the AndroidHarness.
  4. (Restart the jMonkeyEngine)
  5. A Mobile Files node appears in the Project window.
    It lets you edit the MainActivitity.java, the AndroidManifest.xml, and build.properties.

The Android deployment option creates a separate sub-project for android and makes the main project and associated libraries available to the sub-project as libraries. The sub-project can be edited using NBAndroid (see below) or using Eclipse or any other IDE that supports standard android projects. Normally you do not need to edit the android project files. Exceptions are described further below.

Activating the nbandroid plugin in the jMonkeyPlatform is optional, but recommended. You do not need the nbandroid plugin for Android support to work, however nbandroid will not interfere and will in fact allow you to edit the android source files and project more conveniently. To be able to edit, extend and code android-specific code in Android projects, install NBAndroid from the update center:

  1. Open Tools→Plugins→Settings
  2. Go to Tools→Plugins→Available Plugins.
  3. Install the NbAndroid plugin. (Will show up as Android)

Restart the jMonkeyPlatform.

Build and Run

Open your game project in the jMonkeyPlatform.

  1. Right-click the project node and choose Set Main Project.
  2. Right-click the project node to build your project.
    An APK file is created in the "dist" folder.
  3. (Right-click and run the project. The default run target uses the default device set in the Android configuration utility. If you set that to a phone you can run the application directly on your phone!)
  4. Alternatively, select the "Android Device" build configuration next to the Run toolbar button. You can run the project on the emulator (in theory – the emulator doesn’t support OpenGL 2.0 yet?)

Optionally, download

Beta Notes

Android Considerations

You can use the jMonkeyPlatform to save (theoretically) any jMonkeyEngine app as Android app. But the application has to be prepared for the fact that Android devices have a smaller screen resolution, touchscreens instead of mouse buttons, and (typically) no keyboards.

Best Practice: Ideally, you write the core application code in a way that it checks for the environment it's being run on, and automatically adapts the device's limitations by switching off effects, changing input mechanisms etc. Learn how to read graphic card capabilites here.

Using Android specific functions

As described above, you should always try to design your application as platform independent as possible. If your game becomes a sudden hit on android, why not release it on Facebook as an applet as well? When your application is designed in a platform independent way, you don't have to do much more but check a checkbox to deploy your application as an applet. But what if you want to for example access the camera of an android device? Inevitably you will have to use android specific api to access the camera.

Since the main project is not configured to access the android api directly, you have to install NBAndroid (see above) to be able to edit the created android project in the SDK. After installing, click the "open project" button and navigate to the "mobile" folder inside the main project folder (it should show up with an android "a" icon) and open it.

Although you will use android specific api, using a camera is not exactly android specific and so you should try to design this part of the application as platform independent as possible as well. As an example, if you want to use the phones camera as an image input stream for a texture, you can create e.g. the AppState that manages the image and makes it available to the application inside the main project (no android code is needed). Then in the android part of the code you make a connection to the camera and update the image in the AppState. This also allows you to easily support cameras on other platforms in the same way or fallback to something else in case the platform doesn't support a camera.

More Info

The SDK will later provide tools to adapt the material and other graphics settings of the Android deployment version automatically.

view online version