Android deployment via SDK checkbox is HERE!

Hey monkeys,



UPADTE: See the wiki page on jme3 and android for detailed instructions.



in time for beta I finally added android deployment to the SDK!



To use it, you need to install the newly added “Android Support” plugin via Tools->Plugins (nightly update center required of course). Also, you will need the Android SDK from google installed in some folder on your computer.



Go to the jMonkeyEngine SDK settings and set a path to the android SDK, you will also be asked for a path to the android SDK any time you try to use android functions and have set none.





After that you can enable android deployment in the project settings of any normal jme3 “BasicGame” project.





When you enable android deployment a “mobile” folder will be created in the project folder that contains a complete android project with correct settings to run the application using the AndroidHarness, when you build your project, an apk file will be created in the dist folder. Update: An “Android Files” node is added to the project to easily edit the android config and source files.



You can also run the project on the emulator by selecting the “Android Emulator” build configuration next to the run button but the emulator sadly doesn’t support OpenGL 2.0 yet. Update: The run target actually uses the default device set in the android configuration utility, so if you set that to a phone you can run the application directly on your phone!





Work in progress, please test this on all platforms and give feedback, experts may look at nbproject/mobile-impl.xml and suggest other build targets and improvements to the project configuration.



Notes/Hints:

  • 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 but currently not being updated when the main class package or name changes
  • When you disable the mobile deployment option currently the whole “mobile” folder is deleted
  • The “errors” in MainActivity.java are only displayed because the editor doesn’t know the class path of the android project, they are not problematic
  • Installing NBAndroid will allow the editor to recognize the android project class path and get rid of the error marks
  • You do not need the NBAndroid plugin for this to work however it will not interfere and will in fact allow you to edit the android source files and project more conveniently.



    Cheers,

    Normen
11 Likes

wow great!!!

that’s really cool man, I jumped through the Android hoops a month back, check box have been a bit easier.

1 Like

holy smoke, this is great news! this is extremely useful thanks normen < 3

awesome~ but it seems not working for me … the mobile option in the project properties does show up after i set the SDK path. any idea why is this so? :slight_smile:

Its in the “application” subcategory, did you unfold that? If you can see the global options pane you should be able to see the properties too, maybe try to restart the app if the plugin installer didnt do so.

in fact the option is there but the content isn’t



http://i.imgur.com/rVhHF.png



could be something wrong with my SDK?



http://i.imgur.com/1WGrQ.png

Do you get an exception (warning sign in the lower right) when you select the “mobile” entry?

yup here is the the exception detail:



java.lang.NullPointerException

at org.openide.filesystems.FileUtil.toFile(FileUtil.java:970)

at com.jme3.gde.android.AndroidSdkTool.getAndroidToolPath(AndroidSdkTool.java:132)

at com.jme3.gde.android.AndroidSdkTool.getTargetList(AndroidSdkTool.java:141)

at com.jme3.gde.android.MobileCustomizerPanel.updateTargetList(MobileCustomizerPanel.java:38)

at com.jme3.gde.android.MobileCustomizerPanel.(MobileCustomizerPanel.java:32)

at com.jme3.gde.android.MobileCompositeProvider.createComponent(MobileCompositeProvider.java:56)

at org.netbeans.spi.project.ui.support.ProjectCustomizer$DelegateCategoryProvider.create(ProjectCustomizer.java:702)

at org.netbeans.modules.project.uiapi.CustomizerPane.setCategory(CustomizerPane.java:248)

at org.netbeans.modules.project.uiapi.CustomizerPane.access$200(CustomizerPane.java:68)

at org.netbeans.modules.project.uiapi.CustomizerPane$CategoryChangeListener.propertyChange(CustomizerPane.java:333)

at java.beans.PropertyChangeSupport.fire(PropertyChangeSupport.java:335)

at java.beans.PropertyChangeSupport.firePropertyChange(PropertyChangeSupport.java:327)

at java.beans.PropertyChangeSupport.firePropertyChange(PropertyChangeSupport.java:263)

at org.netbeans.modules.project.uiapi.CategoryModel.firePropertyChange(CategoryModel.java:118)

at org.netbeans.modules.project.uiapi.CategoryModel.setCurrentCategory(CategoryModel.java:92)

at org.netbeans.modules.project.uiapi.CategoryView.propertyChange(CategoryView.java:181)

at java.beans.PropertyChangeSupport.fire(PropertyChangeSupport.java:335)

at java.beans.PropertyChangeSupport.firePropertyChange(PropertyChangeSupport.java:327)

at java.beans.PropertyChangeSupport.firePropertyChange(PropertyChangeSupport.java:263)

at org.openide.explorer.ExplorerManager$2.run(ExplorerManager.java:868)

at org.openide.util.Mutex.doEvent(Mutex.java:1341)

at org.openide.util.Mutex.readAccess(Mutex.java:348)

at org.openide.explorer.ExplorerManager.fireInAWT(ExplorerManager.java:865)

at org.openide.explorer.ExplorerManager$1AtomicSetSelectedNodes.fire(ExplorerManager.java:285)

at org.openide.explorer.ExplorerManager.setSelectedNodes(ExplorerManager.java:296)

at org.openide.explorer.ExplorerManager$1SetExploredContextAndSelection.run(ExplorerManager.java:384)

at org.openide.util.Mutex.readAccess(Mutex.java:365)

at org.openide.util.Mutex$1R.run(Mutex.java:1307)

at org.openide.util.Mutex.doWrapperAccess(Mutex.java:1324)

at org.openide.util.Mutex.readAccess(Mutex.java:354)

at org.openide.explorer.ExplorerManager.setExploredContextAndSelection(ExplorerManager.java:411)

at org.openide.explorer.view.BeanTreeView.selectionChanged(BeanTreeView.java:147)

at org.openide.explorer.view.TreeView.callSelectionChanged(TreeView.java:867)

at org.openide.explorer.view.TreeView$TreePropertyListener.run(TreeView.java:1503)

at org.openide.util.Mutex$1Exec.run(Mutex.java:1244)

at org.openide.nodes.Children$ProjectManagerDeadlockDetector.execute(Children.java:1907)

at org.openide.util.Mutex.postRequest(Mutex.java:1250)

at org.openide.util.Mutex.postRequest(Mutex.java:1213)

at org.openide.util.Mutex.postReadRequest(Mutex.java:568)

at org.openide.explorer.view.TreeView$TreePropertyListener.valueChanged(TreeView.java:1473)

at javax.swing.tree.DefaultTreeSelectionModel.fireValueChanged(DefaultTreeSelectionModel.java:634)

at javax.swing.tree.DefaultTreeSelectionModel.notifyPathChange(DefaultTreeSelectionModel.java:1092)

at javax.swing.tree.DefaultTreeSelectionModel.setSelectionPaths(DefaultTreeSelectionModel.java:293)

at javax.swing.tree.DefaultTreeSelectionModel.setSelectionPath(DefaultTreeSelectionModel.java:187)

at javax.swing.JTree.setSelectionPath(JTree.java:1631)

at javax.swing.plaf.basic.BasicTreeUI.selectPathForEvent(BasicTreeUI.java:2371)

at javax.swing.plaf.basic.BasicTreeUI$Handler.handleSelection(BasicTreeUI.java:3587)

at javax.swing.plaf.basic.BasicTreeUI$Handler.mousePressedDND(BasicTreeUI.java:3564)

at javax.swing.plaf.basic.BasicTreeUI$Handler.mousePressed(BasicTreeUI.java:3523)

at java.awt.AWTEventMulticaster.mousePressed(AWTEventMulticaster.java:280)

at java.awt.Component.processMouseEvent(Component.java:6501)

at javax.swing.JComponent.processMouseEvent(JComponent.java:3321)

at java.awt.Component.processEvent(Component.java:6269)

at java.awt.Container.processEvent(Container.java:2229)

at java.awt.Component.dispatchEventImpl(Component.java:4860)

at java.awt.Container.dispatchEventImpl(Container.java:2287)

at java.awt.Component.dispatchEvent(Component.java:4686)

at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4832)

at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4489)

at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4422)

at java.awt.Container.dispatchEventImpl(Container.java:2273)

at java.awt.Window.dispatchEventImpl(Window.java:2713)

at java.awt.Component.dispatchEvent(Component.java:4686)

at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:707)

at java.awt.EventQueue.access$000(EventQueue.java:101)

at java.awt.EventQueue$3.run(EventQueue.java:666)

at java.awt.EventQueue$3.run(EventQueue.java:664)

at java.security.AccessController.doPrivileged(Native Method)

at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)

at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:87)

at java.awt.EventQueue$4.run(EventQueue.java:680)

at java.awt.EventQueue$4.run(EventQueue.java:678)

at java.security.AccessController.doPrivileged(Native Method)

at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)

at java.awt.EventQueue.dispatchEvent(EventQueue.java:677)

at org.netbeans.core.TimableEventQueue.dispatchEvent(TimableEventQueue.java:148)

[catch] at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:211)

at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:128)

at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:117)

at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:113)

at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:105)

at java.awt.EventDispatchThread.run(EventDispatchThread.java:90)

So it looks like you don’t have a tools/android.exe in your sdk folder, you sure its the latest version of the android SDK?

unfortunately itis… the revision 12… T_T

So you have a file e:/Program Files/Android/android-sdk/tools/android.exe ?

Okay, I found out that on windows its a .bat file and I changed the path accordingly…

1 Like

And another fix, the MainActivity was missing a “package” entry…

1 Like

awesome, cheers normen

It works great. Thanks normen! Now just fix the minSdkVersion and there will be magical worlds and unicorns!

Momoko_Fan said:
It works great. Thanks normen! Now just fix the minSdkVersion and there will be magical worlds and unicorns!

Alright, added that too, when a new project is created the minSdkVersion is set to "8". Also removed the double-build when running the application. Now the applications should run directly on an Android device :o

Love it! Thats a great piece of work!



One question. The app installs on my HTC Incredible, but I have to manually run it.



Is there a way to get it to autorun after compilation and installation, or even close and open if already running on the android device?

I don’t know, maybe you can find out if that can be done via the ant build targets of the project somehow. As said, I cannot test this stuff because the emulator does not support OpenGLES 2 and I have no android device.

@normen: you can still test this particular part … In the emulator if the app loads but crashes (opengl error etc) then you know it works