Open an existing JME3 project, or create a new JME3 project.
Right-click the project node in the Projects Window and open the Properties.
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.
(Restart the jMonkeyEngine)
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:
Open Tools→Plugins→Settings
Go to Tools→Plugins→Available Plugins.
Install the NbAndroid plugin. (Will show up as Android)
Right-click the project node and choose Set Main Project.
Right-click the project node to build your project.
An APK file is created in the "dist" folder.
(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!)
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?)
The package name parameter is only used when creating the project and only sets the android MainActivity package name
The needed jMonkeyEngine3.jar for android comes with the plugin and is automatically added to the android build
All non-android project libraries are automatically excluded from the android build. This is currently hard-coded in the build script, check nbproject/mobile-impl.xml for the details.
The main application class parameter for the AndroidHarness is taken from the jme3 project settings when enabling android deployment. Currently it is not updated when you change the main class package or name.
When you disable the mobile deployment option, the whole “mobile” folder is deleted.
The "errors" shown in the MainActivity are wrongly displayed only in the editor and will disappear when you install NBAndroid (see below).
To sign your application, edit the mobile/build.properties file to point at valid keystore files.
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.
Inputs: Devise an alternate control scheme that works for Android users (e.g. using com.jme3.input.controls.TouchListener). This mobile scheme is likely quite different from the desktop scheme.
Effects: Android devices do no support 3D features as well as PCs – or even not at all. E.g. post-processor filters (depth-of-field blur, bloom, light scattering, cartoon, etc), drop shadows, water effects, 3D Audio. Be prepared that these effects will (at best) slow down the application or (in the worst case) not work at all. Provide the option to switch to a low-fi equivalent!
Nifty GUI: Use different base UI layout XML files for the mobile version of your app to account for the different screen settings.
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.
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.