How to run your jme3 application on Android – AndroidHarness

Edit 13.09.2011:

This thread is deprecated.

Please refer to thread



http://hub.jmonkeyengine.org/groups/android/forum/topic/android-deployment-via-checkbox-is-here/





Edit 15.06.2011:

Get the jme3 source via svn from http://jmonkeyengine.googlecode.com/svn/trunk/engine

Build it in jme3 folder with just ‘ant’, or ant clean and then ant if you want to be safe :slight_smile:

I really suggest you get the source if you want to do more than just checking out jme3 android.

Benefits are debugging into jme and always the latest code. No need to wait for the next nightly.

Alternatively you can find the latest nightly in: http://www.jmonkeyengine.com/nightly/

----

Create a android project using nbandroid in netbeans or ADT in eclipse

Add jme3/dist/opt/android/jMonkeyEngine3.jar to your library path

If you need the jme3 demos (like SimpleTexturedTest), add:

jme3/dist/lib/jME3-test.jar and jme3/dist/lib/jME3-testdata.jar

Derive your MainActivity from AndroidHarness and set the application class

[java]import com.jme3.app.AndroidHarness;

public class MainActivity extends AndroidHarness

{

public MainActivity()

{

// Set the application class to run

appClass = “com.test.android.SimpleTexturedTest”;

//eglConfigType = ConfigType.FASTEST; // Default

// Edit 22.06.2011: added a switch to get the highest (best) egl config available on this device

// Its usually RGBA8888

eglConfigType = ConfigType.BEST;

// Exit Dialog title & message

exitDialogTitle = “Exit?”;

exitDialogMessage = “Press Yes”;

// Edit: 25.06.2011: Enable verbose logging

eglConfigVerboseLogging= true;

// Edit: 30.06.2011: Choose screen orientation

screenOrientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;

// Edit 12.07.2011: Invert the MouseEvents X (default = true)

mouseEventsInvertX = true;

// Edit 05.07.2011: Invert the MouseEvents Y (default = true)

mouseEventsInvertY = true;

}

}[/java]

Copy all your textures, models, aso to the asset folder in your android project

Finished, Run

AndroidHarness features:

Android touch events are translated into Mouse events

An unhandled exception handler, so no more black screens

Lifecycle management

Edit 24.05.2011:

Fixed app lifecycle. If you leave your activity with the back key the app will be destroyed, if you use the home key the app gets frozen in the background. You can return to it and it will be in the same state as when you left it.

Edit 27.05.2011:

Do NOT copy Common and Interface/Fonts folder to assets, they are loaded from jar now.

Edit 30.05.2011:

CubeMap / Sky is now working, but you have to use an android specific class: AndroidSkyFaktory

[java]import com.jme3.util.android.AndroidSkyFactory;

public class TestSkyLoading extends SimpleApplication {

public void simpleInitApp() {

Texture west = assetManager.loadTexture(“Textures/Sky/Lagoon/lagoon_west.jpg”);

Texture east = assetManager.loadTexture(“Textures/Sky/Lagoon/lagoon_east.jpg”);

Texture north = assetManager.loadTexture(“Textures/Sky/Lagoon/lagoon_north.jpg”);

Texture south = assetManager.loadTexture(“Textures/Sky/Lagoon/lagoon_south.jpg”);

Texture up = assetManager.loadTexture(“Textures/Sky/Lagoon/lagoon_up.jpg”);

Texture down = assetManager.loadTexture(“Textures/Sky/Lagoon/lagoon_down.jpg”);

Spatial sky = AndroidSkyFactory.createSky(assetManager, west, east, north, south, up, down);

rootNode.attachChild(sky);

}

}[/java]

Edit 14.06.2011:

Dont use TGA textures, there seems to be a color channel bug. Use JPG or PNG instead.

Edit 21.06.2011:

Fixed bug in egl config chooser and depth is forced to 16 bit.

Added switch for use in your activity derived from AndroidHarness:

[java]

eglConfigType = ConfigType.FASTEST; // Get default android EGL config: RGB565

// or

eglConfigType = ConfigType.BEST; // Get best android EGL config on this device, usually RGBA8888

[/java]

Edit 22.06.2011

Exit dialog messages are now customizable

[java]

exitDialogTitle = “Exit?”;

exitDialogMessage = “Press Yes”;

[/java]

Edit 25.06.2011:

Enable logging for the EGL config chooser in your main activity:

[java]eglConfigVerboseLogging = true[/java]

Edit 26.06.2011:

Make sure you have enough memory allocated to eclipse:

Change the memory settings in eclipse.ini

-Xms128m -Xmx512m

Or if you have really lots of memory

-Xms1024m -Xmx2048m

Edit 12.07.2011:

Added screen resolution setting to AndroidHarness and allow mouse X/Y flip.

6 Likes

Maybe I should add that you can create Android projects using jMP already by simply installing NBAndroid. You can install the plugin via the update center when you add the following URL to your update center list (Tools->Plugins->Settings)

http://deadlock.netbeans.org/hudson/job/nbandroid/lastStableBuild/artifact/build/updates/updates.xml

In the future jMP projects will simply have another distribution checkbox with some parameters like they have now for Desktop, Applet and WebStart distribution.




The jMonkeyEngine SDK can now distribute normal projects for android, see this post:

http://hub.jmonkeyengine.org/groups/android/forum/topic/android-deployment-via-checkbox-is-here/

appClass cannot be resolved to a variable


Why ? :(

I just committed some fixes, pls try to update your svn.

Nope, still the same…

so you forgot the “extends AndroidHarness”

I have this code:



[java]package com.lesmobilizers.helloandroidharness;



import com.jme3.app.AndroidHarness;



public class MainActivity extends AndroidHarness {

public MainActivity() {

appClass = “com.lesmobilizers.helloandroidharness.apps.SimpleTexturedTest”;

}

}[/java]



Which is pretty much the same as larynx’s one.

Sometime eclipse doesnt recognize that a jar was changed. Remove the jMonkeyEngine3.jar from your library path, Ok - back out, and then add it again. Also make sure you did a recompile of jme3 with ant clean, ant

I did it all again from the beginning and it now works… weird. Thx !

Add jme3/dist/opt/android/jMonkeyEngine3.jar to your library path

I am trying to run jme3 on my Tmobile myTouch. I have retrieved the source and compiled. I created the sample app as in the first entry in this thread. I try to run and I get this log:





06-09 13:29:23.595: INFO/AndroidRuntime(398): NOTE: attach of thread ‘Binder Thread #3’ failed

06-09 13:29:23.674: INFO/ActivityManager(59): Start proc rds.jme for activity rds.jme/.MainActivity: pid=405 uid=10037 gids={}

06-09 13:29:24.195: INFO/jdwp(405): Ignoring second debugger – accepting and dropping

06-09 13:29:24.205: DEBUG/dalvikvm(32): GC_EXPLICIT freed 267 objects / 10232 bytes in 478ms

06-09 13:29:24.395: DEBUG/dalvikvm(32): GC_EXPLICIT freed 27 objects / 1184 bytes in 126ms

06-09 13:29:24.594: DEBUG/dalvikvm(32): GC_EXPLICIT freed 2 objects / 64 bytes in 149ms

06-09 13:29:25.264: ERROR/dalvikvm(405): Could not find class ‘[Ljava.awt.image.BufferedImage;’, referenced from method com.jme3.system.AppSettings.getIcons

06-09 13:29:25.264: WARN/dalvikvm(405): VFY: unable to resolve check-cast 1582 ([Ljava/awt/image/BufferedImage;) in Lcom/jme3/system/AppSettings;

06-09 13:29:25.264: DEBUG/dalvikvm(405): VFY: replacing opcode 0x1f at 0x0006

06-09 13:29:25.264: DEBUG/dalvikvm(405): VFY: dead code 0x0008-000a in Lcom/jme3/system/AppSettings;.getIcons ()[Ljava/awt/image/BufferedImage;

06-09 13:29:25.285: WARN/dalvikvm(405): VFY: unable to find class referenced in signature ([Ljava/awt/image/BufferedImage;)

06-09 13:29:25.394: INFO/JmeSystem(405): Running on jMonkey Engine 3 ALPHA 0.6 Android

06-09 13:29:25.435: INFO/AndroidHarness(405): onStart

06-09 13:29:25.445: INFO/AndroidHarness(405): onResume

06-09 13:29:25.854: DEBUG/libEGL(405): egl.cfg not found, using default config

06-09 13:29:25.864: DEBUG/libEGL(405): loaded /system/lib/egl/libGLES_android.so

06-09 13:29:25.934: WARN/dalvikvm(405): threadid=7: thread exiting with uncaught exception (group=0x4001d800)

06-09 13:29:25.954: ERROR/AndroidRuntime(405): FATAL EXCEPTION: GLThread 8

06-09 13:29:25.954: ERROR/AndroidRuntime(405): java.lang.IllegalArgumentException: No configs match configSpec

06-09 13:29:25.954: ERROR/AndroidRuntime(405): at android.opengl.GLSurfaceView$BaseConfigChooser.chooseConfig(GLSurfaceView.java:760)

06-09 13:29:25.954: ERROR/AndroidRuntime(405): at android.opengl.GLSurfaceView$EglHelper.start(GLSurfaceView.java:916)

06-09 13:29:25.954: ERROR/AndroidRuntime(405): at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1246)

06-09 13:29:25.954: ERROR/AndroidRuntime(405): at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1116)

06-09 13:29:25.984: INFO/ActivityManager(59): Displayed activity rds.jme/.MainActivity: 2350 ms (total 776824 ms)

06-09 13:29:26.105: WARN/ActivityManager(59): Force finishing activity rds.jme/.MainActivity



This is the source:



package rds.jme;

import com.jme3.app.AndroidHarness;

public class MainActivity extends AndroidHarness {

public MainActivity()

{

appClass = “jme3test.android.SimpleTexturedTest”;

}

}



Any help would be greatly appreciated.

Your phone probably doesn’t support OpenGL ES 2.0.

As far as I can tell, my phone has Opengl ES 2.0. The phone is on android 2.2. Also, I found a demo game that requires ES 2.0 and it ran ok. I saw somewhere a test program for Android to test the gl version but I cannot find it right now.



Morris

Interesting - no matching GL config. Maybe just rgb565 is not supported, i would have to add code to spit out the configs which are supported.

I also think that android 2.2 means OpenGL ES2.0 is supported.



Did you try the app from the market?

Yes, I tried the app from the market. It showed the chooser but all the apps failed. Is there some utility available that I could run to verify the status of OpenGL ES?

I will add some code to the context creation to show more info. Should be in the svn by tomorrow

Ok. Thanks. I’ll look for new stuff tomorrow.

Hey there,

just started developing with jmonkey. I faced, the same problem like morrisford.

I modified the project, thus it loads my own TestAppClass deriving from SimpleApplication. At first it didn’t work out. That was until I changed the material to Unshaded.j3md. Looks like the “SolidColor.j3md” isn’t working on my device (Samsung Galaxy Mini).

Maybe this helps…

Here’s my testclass:

[java]

public class TestAppClass extends SimpleApplication {

@Override

public void simpleInitApp() {

Box b=new Box(Vector3f.ZERO,1,1,1);

Geometry geom = new Geometry(“Box”,b);

Material mat=new Material(assetManager, “Common/MatDefs/Misc/Unshaded.j3md”);

mat.setColor(“Color”, ColorRGBA.Blue);

geom.setMaterial(mat);

rootNode.attachChild(geom);

}

}

[/java]

1 Like

Update: The java.lang.IllegalArgumentException: No configs match configSpec still exists, when trying to run the android build within the simulator though…

There is no OpenGLES2.0 simulator available, nag google about it.