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!
thanks alot buddy :)
ReplyDeleteI'm glad I could help :)
DeleteI can't solve java.lang.UnsatisfiedLinkError );
ReplyDeleteI copied armeabi, armeabi-v7a, mips and x86 to my new folder lib,
and I compressed and changed to lib.jar, and I added: compile fileTree(include: ['*.jar']) in my build.gradle dependency.
What can be the problem?
Thank you too much for the guide.
Could you send me a copy of your project?
DeleteHere it is https://github.com/AlexBruch/DisIsEspain4
DeleteThanks!
It works!
DeleteI'm so sorry I put the .jar in the wrong place :/// because my bad english ;)
A thousands thanks!!!
You're welcome. Glad to hear that the method still works!
DeleteDo you know how to setup in Android Studio 1.2.2? There is no org folder.
ReplyDeleteThat happens to me too. Try ../org instead and tell me your results.
Deleterm: ../org: No such file or directory
DeleteNo, I mean mv. The rm step reems to be done already. First run "cd <project folder>/AndEngine/src/main" and then "mv ../org java".
Delete"mv: rename ../org to java/org: No such file or directory", thanks a lot, Joel, but I have spent too much time on this problem and I am using cocos2d now, after all , thanks from the back of the earth :)
DeleteOk, good luck with your project!
DeleteHello,
ReplyDeleteHow to make changes if I am not using git but directly download zip and add to project ??
Hello, in the zip file there should be a single directory AndEngine-GLES2, which corresponds to AndEngine.github. Extract it and keep following the steps from there, starting with the rsync command. Make sure you're in the right directory and everything.
Delete