Eclipse + jME3 + Android + JNI/NDK

Will ammend as time allows:

Steps to create a working environment for Jmonkey in Android Studio.

Steps:

  1. Create a class that extends SimpleApplication
  2. Create a class that extends com.jme3.app.AndroidHarness and reference our SimpleApplicaton extended class in the provided protected fields.
  3. Declare the class that extended AndroidHarness in AndroidManifest.xml

An example class that extends SimpleApplication. Note that we have no static void main(String[] args) but we can still use the noArgs class constructor.

package com.jayfella.motorunner;

public class JmeGame extends SimpleApplication {

    public JmeGame() {
        // super(new AppState[0]);
    }

    @Override
    public void simpleInitApp() {

        // 0, 0, 0 reference
        Box box = new Box(1, 1, 1);
        Geometry geom = new Geometry("box", box);
        Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
        mat.setColor("Color", ColorRGBA.Blue);

        rootNode.attachChild(geom);
    }
}

An example file that extends AndroidHarness. Note that we reference our SimpleApplication extended class here and use protected fields to set any AppSettings.

package com.jayfella.motorunner;

import android.os.Bundle;

import com.jme3.app.AndroidHarness;

import java.util.logging.Level;
import java.util.logging.LogManager;

/**
 * Created by James on 12/01/2018.
 */

public class JmeHarness extends AndroidHarness {

    public JmeHarness() {

        // Set the desired EGL configuration
        eglBitsPerPixel = 24;
        eglAlphaBits = 0;
        eglDepthBits = 16;
        eglSamples = 0;
        eglStencilBits = 0;

        // Set the maximum framerate
        // (default = -1 for unlimited)
        frameRate = -1;

        // Set main project class (fully qualified path)
        // the class that extends SimpleApplication
        appClass = "com.jayfella.motorunner.JmeGame";

        // Set input configuration settings
        joystickEventsEnabled = true;
        keyEventsEnabled = true;
        mouseEventsEnabled = true;

        // Set application exit settings
        finishOnAppStop = true;
        handleExitHook = true;
        exitDialogTitle = "Do you want to exit?";
        exitDialogMessage = "Use your home key to bring this app into the background or exit to terminate it.";

        // Set splash screen resource id, if used
        // (default = 0, no splash screen)
        // For example, if the image file name is "splash"...
        //     splashPicID = R.drawable.splash;
        splashPicID = 0;
        // splashPicID = R.drawable.jme_white;

        // Set the default logging level (default=Level.INFO, Level.ALL=All Debug Info)
        LogManager.getLogManager().getLogger("").setLevel(Level.INFO);

    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

}

Declare the class to launch on start in ./manifests/AndroidManifest.xml

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.jayfella.motorunner">

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">

       // the entry point class that extends com.jme3.app.AndroidHarness
        <activity
            android:name="com.jayfella.motorunner.JmeHarness"
            android:label="@string/app_name"
            android:launchMode="singleTask"
            android:screenOrientation="landscape">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

    </application>

    <!-- Tell the system that you need ES 2.0. -->
    <uses-feature
        android:glEsVersion="0x00020000"
        android:required="true"/>

    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
    <uses-permission android:name="android.permission.READ_PHONE_STATE"/>
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
    <uses-permission android:name="android.permission.VIBRATE"/>

</manifest>

The XML file is essentially the start point for all android applications. The XML file launches the JmeHarness class that you provided. The JmeHarness class sets AppSettings and states the class that extends SimpleApplication. The SimpleApplication class is then invoked with the given settings. Game on.

1 Like