PageRenderTime 46ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/sdk/jme3-core/javahelp/com/jme3/gde/core/docs/jme3/android.html

http://jmonkeyengine.googlecode.com/
HTML | 303 lines | 242 code | 50 blank | 11 comment | 0 complexity | dc271e10a7f07a66d04cb023429dd888 MD5 | raw file
Possible License(s): LGPL-2.0, GPL-2.0, BSD-3-Clause
  1. <h1><a>Android Support in the jMonkeyEngine</a></h1>
  2. <div>
  3. <p>
  4. This is a draft of a feature that is work in progress. If you have questions or suggestions, please leave a comment on the <object classid="java:org.netbeans.modules.javahelp.BrowserDisplayer"><param name="content" value="http://jmonkeyengine.org/groups/android/forum/topic/android-deployment-via-checkbox-is-here"><param name="text" value="<html><u>Android forum thread</u></html>"><param name="textColor" value="blue"></object>!
  5. </p>
  6. </div>
  7. <!-- EDIT1 SECTION "Android Support in the jMonkeyEngine" [1-294] -->
  8. <h2><a>Requirements</a></h2>
  9. <div>
  10. </div>
  11. <!-- EDIT2 SECTION "Requirements" [295-317] -->
  12. <h3><a>Developer Requirements</a></h3>
  13. <div>
  14. <ul>
  15. <li><div> Install <object classid="java:org.netbeans.modules.javahelp.BrowserDisplayer"><param name="content" value="http://developer.android.com/sdk/index.html"><param name="text" value="<html><u>Android SDK 2.2</u></html>"><param name="textColor" value="blue"></object> or better.</div>
  16. </li>
  17. <li><div> Install jMonkeyEngine <acronym title="Software Development Kit">SDK</acronym></div>
  18. </li>
  19. <li><div> (Optional) Install NBAndroid in the jMonkeyEngine <acronym title="Software Development Kit">SDK</acronym>:</div>
  20. <ol>
  21. <li><div> Go to Tools?Plugins?Available Plugins.</div>
  22. </li>
  23. <li><div> Install the &quot;Android&quot; plugin.</div>
  24. </li>
  25. </ol>
  26. </li>
  27. </ul>
  28. </div>
  29. <!-- EDIT3 SECTION "Developer Requirements" [318-609] -->
  30. <h3><a>User Requirements</a></h3>
  31. <div>
  32. <ul>
  33. <li><div> Android 2.2 device or better</div>
  34. </li>
  35. <li><div> Graphic card that supports OpenGL ES 2.0 or better</div>
  36. </li>
  37. <li><div> <object classid="java:org.netbeans.modules.javahelp.BrowserDisplayer"><param name="content" value="http://jmonkeyengine.org/groups/android/forum/topic/does-my-phone-meet-the-requirements-necessary-to-run-jmonkeyengine-3/"><param name="text" value="<html><u>Does my phone meet the requirements necessary to run jMonkeyEngine 3?</u></html>"><param name="textColor" value="blue"></object></div>
  38. </li>
  39. </ul>
  40. </div>
  41. <!-- EDIT4 SECTION "User Requirements" [610-925] -->
  42. <h2><a>Features</a></h2>
  43. <div>
  44. </div>
  45. <!-- EDIT5 SECTION "Features" [926-945] -->
  46. <h3><a>JMonkeyEngine3 Android Integration</a></h3>
  47. <div>
  48. <ul>
  49. <li><div> Android touch events are translated into mouse events.</div>
  50. </li>
  51. <li><div> No more unhandled exceptions (i.e. no more black screens)</div>
  52. </li>
  53. <li><div> Lifecycle management</div>
  54. <ul>
  55. <li><div> Leaving the activity with the Back key destroys the app (quit).</div>
  56. </li>
  57. <li><div> Leaving the activity with the Home key freezes the app in the background. When you return, the app is in the same state as when you left it (pause).</div>
  58. </li>
  59. </ul>
  60. </li>
  61. <li><div> Currently supports all jmetests except:</div>
  62. <ul>
  63. <li><div> Framebuffers - WIP</div>
  64. </li>
  65. <li><div> Shadows - WIP</div>
  66. </li>
  67. <li><div> Water - not tested yet</div>
  68. </li>
  69. </ul>
  70. </li>
  71. </ul>
  72. </div>
  73. <!-- EDIT6 SECTION "JMonkeyEngine3 Android Integration" [946-1479] -->
  74. <h3><a>jMonkeyEngine SDK Android Integration</a></h3>
  75. <div>
  76. <p>
  77. Mobile deployment is a &quot;one-click&quot; option next to Desktop/WebStart/Applet deployment in the jMonkeyEngine <acronym title="Software Development Kit">SDK</acronym>.
  78. </p>
  79. <ul>
  80. <li><div> Automatic creation of Android harness and settings.</div>
  81. </li>
  82. <li><div> Ant script build target creates APK file.</div>
  83. </li>
  84. <li><div> Ant script run target executes APK on Android Emulator or mobile device.</div>
  85. </li>
  86. </ul>
  87. </div>
  88. <!-- EDIT7 SECTION "jMonkeyEngine SDK Android Integration" [1480-1823] -->
  89. <h2><a>Beta Instructions</a></h2>
  90. <div>
  91. <ol>
  92. <li><div> Make sure you have installed the Android Project Support into the jMonkeyEngine <acronym title="Software Development Kit">SDK</acronym>.</div>
  93. </li>
  94. <li><div> Open the jMonkeyEngine <acronym title="Software Development Kit">SDK</acronym> Options&gt;Mobile and enter the path to your Android <acronym title="Software Development Kit">SDK</acronym> directory, and click OK. E.g. <code>/opt/android-sdk</code></div>
  95. </li>
  96. </ol>
  97. </div>
  98. <h4><a>Activate Android Deployment</a></h4>
  99. <div>
  100. <ol>
  101. <li><div> Open an existing JME3 project, or create a new JME3 project.</div>
  102. </li>
  103. <li><div> Right-click the project node in the Projects Window and open the Properties.</div>
  104. </li>
  105. <li><div> In the Application&gt;Mobile Properties, enable Mobile Deployment, and select an Android target. <br/>
  106. This creates a &quot;mobile&quot; folder in your projects directory. This folder contains a complete android project with correct settings to run the application using the AndroidHarness.</div>
  107. </li>
  108. <li><div> (Restart the jMonkeyEngine)</div>
  109. </li>
  110. <li><div> A Mobile Files node appears in the Project window. <br/>
  111. It lets you edit the MainActivitity.java, the AndroidManifest.xml, and build.properties.</div>
  112. </li>
  113. </ol>
  114. <p>
  115. <img src="nbdocs:/com/jme3/gde/core/docs/jme3/nvyyd.png">
  116. </p>
  117. <p>
  118. 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. <em>The libraries are first added to the android sub-project when the main project is built for the first time.</em>
  119. </p>
  120. </div>
  121. <h4><a>Build and Run</a></h4>
  122. <div>
  123. <p>
  124. Open your game project in the jMonkeyEngine <acronym title="Software Development Kit">SDK</acronym>.
  125. </p>
  126. <p>
  127. <strong>Building</strong>
  128. </p>
  129. <ol>
  130. <li><div> Right-click the project node to build your project. <br/>
  131. An APK file is created in the &quot;dist&quot; folder.</div>
  132. </li>
  133. </ol>
  134. <p>
  135. <strong>Running</strong>
  136. </p>
  137. <ol>
  138. <li><div> Right-click the project node and choose Set Main Project.</div>
  139. </li>
  140. <li><div> Select the &quot;Android Device&quot; build configuration next to the Run toolbar button.</div>
  141. </li>
  142. <li><div> <em>Make sure &quot;Compile on Save&quot; is disabled in your project preferences.</em></div>
  143. </li>
  144. <li><div> Run the application on a connected phone by right-clicking it and selecting &quot;Run&quot; or press the &quot;Play&quot; button in the toolbar.</div>
  145. </li>
  146. <li><div> The application will run and output its log to the &quot;Output&quot; window of the <acronym title="Software Development Kit">SDK</acronym>.</div>
  147. </li>
  148. <li><div> When finished testing, click the &quot;x&quot; next to the run status in the lower right to quit the logging output.</div>
  149. </li>
  150. </ol>
  151. <p>
  152. The default android 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, the emulator does not support OpenGLES 2.0 and cannot run the engine.
  153. </p>
  154. <p>
  155. Optionally, download <object classid="java:org.netbeans.modules.javahelp.BrowserDisplayer"><param name="content" value="http://code.google.com/p/jmonkeyengine/downloads/detail?name=Jme3Beta1Demo.apk&amp;can=1&amp;q="><param name="text" value="<html><u>Jme3Beta1Demo.apk</u></html>"><param name="textColor" value="blue"></object>
  156. </p>
  157. <p>
  158. During build, the libraries and main jar file from the main project are copied to the android project libs folder for access. During this operation the desktop-specific libraries are replaced with android specific JARs.
  159. </p>
  160. <p>
  161. <strong>Be aware that logging has been identified as having a significant performance hit in Android applications. If getting poor performance please try turning logging either down or off and retesting.</strong>
  162. </p>
  163. </div>
  164. <h4><a>Installing NBAndroid</a></h4>
  165. <div>
  166. <p>
  167. Activating the nbandroid plugin in the jMonkeyEngine <acronym title="Software Development Kit">SDK</acronym> 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:
  168. </p>
  169. <ol>
  170. <li><div> Open Tools?Plugins?Settings</div>
  171. </li>
  172. <li><div> Go to Tools?Plugins?Available Plugins.</div>
  173. </li>
  174. <li><div> Install the NbAndroid plugin. (Will show up as Android)</div>
  175. </li>
  176. </ol>
  177. </div>
  178. <h4><a>Notes</a></h4>
  179. <div>
  180. <ul>
  181. <li><div> The package name parameter is only used when creating the project and only sets the android MainActivity package name</div>
  182. </li>
  183. <li><div> The needed android.jar comes with the plugin and is automatically added to the android build</div>
  184. </li>
  185. <li><div> 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.</div>
  186. </li>
  187. <li><div> 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.</div>
  188. </li>
  189. <li><div> When you disable the mobile deployment option, the whole “mobile” folder is deleted.</div>
  190. </li>
  191. <li><div> The &quot;errors&quot; shown in the MainActivity are wrongly displayed only in the editor and will disappear when you install NBAndroid (see below).</div>
  192. </li>
  193. <li><div> To sign your application, edit the mobile/build.properties file to point at valid keystore files.</div>
  194. </li>
  195. </ul>
  196. </div>
  197. <!-- EDIT8 SECTION "Beta Instructions" [1824-6350] -->
  198. <h2><a>Android Considerations</a></h2>
  199. <div>
  200. <p>
  201. You can use the jMonkeyEngine <acronym title="Software Development Kit">SDK</acronym> 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.
  202. </p>
  203. <ul>
  204. <li><div> <strong>Inputs:</strong> 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.</div>
  205. </li>
  206. <li><div> <strong>Effects:</strong> Android devices do no support 3D features as well as PCs – or even not at all. This restriction includes 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! </div>
  207. </li>
  208. <li><div> <strong>Nifty <acronym title="Graphical User Interface">GUI</acronym>:</strong> Use different base UI layout <acronym title="Extensible Markup Language">XML</acronym> files for the mobile version of your app to account for a different screen resolution.</div>
  209. </li>
  210. </ul>
  211. <p>
  212. <strong>Best Practice:</strong> Ideally, you write the core application code in a way that it checks for the environment it&#039;s being run on, and automatically adapts the device&#039;s limitations by switching off effects, changing input mechanisms etc. Learn how to <a href="/com/jme3/gde/core/docs/jme3/advanced/read_graphic_card_capabilites.html">read graphic card capabilites</a> here.
  213. </p>
  214. </div>
  215. <!-- EDIT9 SECTION "Android Considerations" [6351-7717] -->
  216. <h2><a>Using Android specific functions</a></h2>
  217. <div>
  218. <p>
  219. 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&#039;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.
  220. </p>
  221. <p>
  222. 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 <acronym title="Software Development Kit">SDK</acronym>. After installing, click the &quot;open project&quot; button and navigate to the &quot;mobile&quot; folder inside the main project folder (it should show up with an android &quot;a&quot; icon) and open it.
  223. </p>
  224. <p>
  225. <img src="nbdocs:/com/jme3/gde/core/docs/jme3/android_access.png">
  226. 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&#039;t support a camera.
  227. </p>
  228. <p>
  229. Note that you have to build the whole project once to make (new) classes in the main project available to the android part.
  230. </p>
  231. </div>
  232. <!-- EDIT10 SECTION "Using Android specific functions" [7718-9498] -->
  233. <h2><a>More Info</a></h2>
  234. <div>
  235. <p>
  236. The <acronym title="Software Development Kit">SDK</acronym> will later provide tools to adapt the material and other graphics settings of the Android deployment version automatically.
  237. </p>
  238. <ul>
  239. <li><div> <object classid="java:org.netbeans.modules.javahelp.BrowserDisplayer"><param name="content" value="http://jmonkeyengine.org/groups/android/forum/topic/android-deployment-via-checkbox-is-here"><param name="text" value="<html><u>Android Forum Thread (beta)</u></html>"><param name="textColor" value="blue"></object></div>
  240. </li>
  241. <li><div> <object classid="java:org.netbeans.modules.javahelp.BrowserDisplayer"><param name="content" value="http://jmonkeyengine.org/groups/android/forum/topic/how-to-run-your-jme3-application-on-android-androidharness"><param name="text" value="<html><u>Android Forum Thread (alpha)</u></html>"><param name="textColor" value="blue"></object></div>
  242. </li>
  243. </ul>
  244. <div><span>
  245. <a href="/wiki/doku.php/tag:documentation?do=showtag&amp;tag=tag%3Adocumentation">documentation</a>,
  246. <a href="/wiki/doku.php/tag:sdk?do=showtag&amp;tag=tag%3Asdk">sdk</a>,
  247. <a href="/wiki/doku.php/tag:android?do=showtag&amp;tag=tag%3Aandroid">android</a>,
  248. <a href="/wiki/doku.php/tag:deployment?do=showtag&amp;tag=tag%3Adeployment">deployment</a>,
  249. <a href="/wiki/doku.php/tag:tool?do=showtag&amp;tag=tag%3Atool">tool</a>
  250. </span></div>
  251. </div>
  252. <!-- EDIT11 SECTION "More Info" [9499-] -->
  253. <p><em><a href="http://jmonkeyengine.org/wiki/doku.php/jme3:android?do=export_xhtmlbody">view online version</a></em></p>