This guide assumes that you have Android Studio, git, a terminal and rsync installed.
- Create and open the project in which AndEngine will be used.
- Create a module for AndEngine.
File → Project Structure → Modules → + → Android Library → [Module name: AndEngine, Package name: org.andengine, Create activity: no] → Finish
- Tell the compiler to search the AndEngine module by adding a dependency.
File → Project Structure → Modules → <the module that will use AndEngine> → Dependencies → + → Module dependency → :AndEngine
- Download AndEngine by running the following in a terminal:
$ cd <project folder> $ git clone -b <GLES2 or GLES2-AnchorCenter> https://github.com/nicolasgramlich/AndEngine.git AndEngine.github $ rsync -a AndEngine.github/* AndEngine # This merges AndEngine.github and AndEngine $ rm -rf AndEngine.github
- Make a minor change to the file tree of AndEngine to make it work with Android Studio.
$ cd <project folder>/AndEngine/src/main $ rm -r java/org $ mv org java
- Ensure that Android Studio notices the changes you did. Do this by right clicking on the AndEngine module in the Project tool window and choosing Synchronize 'AndEngine'.
Optional: adding an extension
Adding an extension is much the same procedure, so I'll only list the additional things you need to do.
- Before 2: To find the package name of the extension, browse the extension repo on github and look in AndroidManifest.xml.
- After 3: Make the extension dependent on AndEngine.
- At 5: This step may vary slightly. You may not need to do anything.
Fixing java.lang.UnsatisfiedLinkError
When I tried to use the physics extension, everything compiled fine, but when I ran my app, it crashed, logging: java.lang.UnsatisfiedLinkError: Couldn't load andenginephysicsbox2dextension from loader dalvik.system.PathClassLoader[...]: findLibrary returned null
That is, the .so files are not in the apk. Workaround:
- Manually copy <extension-module>/libs/* to a new folder <main-module>/lib
- Compress lib/ to lib.zip
- Rename lib.zip to lib.jar
- Add compile files('lib.jar') as a dependency in <main-module>/build.gradle
Happy coding!