Hi!
This is the devlog for
@CarniBlood and @PouleyKetchoup's LibGDXjam project.
We decided we will make a game for both Android phones/tablets and desktop.
As I said in my
self-introduction, I'm mostly coding on my smartphone using AndroidIDE as main work environment.
In this post, I will explain how I setup a LibGDX project on Android, also compatible with Eclipse on the desktop.
Since AndroidIDE introduced basic Gradle support in a (relatively) recent update, I tried to setup the project with the recommended Gradle-based environment. This didn't worked out, so I ended up compiling LibGDX from source and setup a more AndroidIDE-friendly environment. I will detail both methods for reference.
A. The method that didn't work on Android: Gradle-based setup
The main idea was to setup a standard LibGDX dev project on desktop, and try to make it work with AndroidIDE directly.
1) On desktop, I created a new LibGDX project with gdx-setup.jar
2) I followed this
wiki to make it work on desktop.
3) I created a new git repository with this project's files and retrieve it on Android (see annexe for git on Android)
4) With the file hierarchy provided by this LibGDX setup, AndroidIDE failed to consider it as a Gradle project, maybe because there is an "AndroidManifest.xml" in the Android root folder, so it will just load it as a basic Android project and try to compile java directly.
5) There is one option in AndroidIDE to create a new Gradle project:
When created this way, the root android folder contains only build.gradle, and the "AndroidManifest.xml" is in src/main subfolder. This way only AndroidIDE seems to open it well as a Gradle project, so I used this file hierarchy and "build.gradle" (the one generated by AndroidIDE) and manually add LibGDX dependencies and pre-build tasks from previous "build.gradle" (the one generated by gdx-setup.jar).
6) And... it didn't work! It seems many options in the build.gradle needed by LibGDX setup are not recognized yet by AndroidIDE.
So I moved to the second method below.
B. The method that worked: AndroidIDE project + LibGDX from source
The main idea is to create a project in AndroidIDE first, and compile LibGDX from source to use the latest version for the project.
With this method, I still need to work on a desktop environment to compile and update the LibGDX libs to a newer version.
1) AndroidIDE have an option to create a "New Mobile Game (with libGDX/Java)" in "Create new project..." menu:
2) This compiles and works perfectly in Android obviously, but still is only setup for Android platform (not desktop or others) and the libGDX version is pretty old one.
3) I also had to manually change the "$project_name$" in gdx-game/.project and gdx-game-android/.project to match the folder name (someway AndroidIDE failed to fill it properly).
4) After creating a git repository out of this sample project (see annexe for git on Android),
I imported the project in Eclipse to finish to setup:
- gdx-game folder imported as existing Java project
- gdx-game-android imported as existing Android project
5) On desktop again, I had to build LibGDX from source to get the latest version for the project.
- First, I cloned the git repository: git@github.com:libgdx/libgdx.git
- Then, as described in
this wiki, in the root folder, I invoked the command "ant -f fetch.xml" followed by "ant".
6) Now the latest LibGDX jars have been generated in the subfolder "dist", and I copied the following files to the game project folder:
- "libgdx.jar" to "gdx-game/libs",
- "gdx-backend-android.jar" to "gdx-game-android/libs",
- "armeabi/libgdx.so" to "gdx-game-android/libs/armeabi",
- "armeabi-v7a/libgdx.so" to "gdx-game-android/libs/armeabi-v7a",
- "x86/libgdx.so" to "gdx-game-android/libs/x86".
7) Then I had to manually create the gdx-game-desktop folder for the desktop version of the project,
- with a new ".classpath" file (
example) in "gdx-game-desktop" root folder
- and a new "DesktopLauncher.java" file (
example) in "gdx-game-desktop/src/com/[company]/[name]" folder
8) I copied LibGDX jars for desktop from files previously generated from source (in "dist" folder) to "gdx-game-dekstop/libs"
:
- "gdx-backend-lwjgl.jar"
- "gdx-backend-lwjgl-natives.jar"
- "gdx-natives.jar"
9) I imported the desktop project in Eclipse as existing java project.
10) There is one more step to be able to share the same asset folder between Android and desktop version.
In the Android project, assets are located in "gdx-game-android/assets", and I had to add this folder as external linked folder to the desktop project in eclipse, so all content from Android assets folder is automatically copied to desktop bin folder when generating dekstop project. For this, I found a method inspired by this wiki:
- On the top level of gdx-game-dekstop project in Eclipse, right click and select "New > Folder".
- In the "new Folder" dialog, click the "Advanced" button.
- Select "Link to Alternated Location" radio button
- Type in the blank folder path: "PARENT-1-PROJECT_LOC\gdx-game-android\assets", and "Finish".
- On the top level of gdx-game-dekstop project in Eclipse, right click and select "Properties".
- In "Java Build Path > Source", click the "Add Folder.." button and select the newly created "assets" folder, and click "OK" twice.
11) And that's it! Now there is a project environment working both on desktop with Eclipse, and on Android with AndroidIDE!
Annexe. How to use git on Android
1) I used
TerminalIDE for a good console environment.
2) To setup SSH in TerminalIDE, see
http://stackoverflow.com/a/22062806
3) Also there is one issue that TerminalIDE cannot resolve domain names directly,
so if I try "git clone git@github.com:myusername/myrepo.git" it will not work.
First, I should type "jping github.com" or "jping bitbucket.org" (depending which hosting service you use) to resolve the ip : XX.XX.XX.XX and then I can do "git clone git@XX.XX.XX.XX:myusername/myrepo.git".
4) After that, I can do all git commit/pull/push/branch/merge/rebase prefectly in console!
Just be aware, Android smartphones are not very stable environments for git, and it may fail sometimes when it become too heavy in memory. Also, git sometimes think there are modified files and refuse to do one operation, even if there is no local modifications (seems to be due to issues with Android OS). So I advise you to avoid as much as possible to perform complicated merges, and to work only on one branch by ourself, to be sure to always merge fast-forward.
It's also possible to use AndroidIDE to handle git commits with a graphical interface. It's also supposed to handle branching and pull from remote, but since it silently fails on any conflict encountered, it's not very practical to use for this purpose. most of the time I use it only to visualize the changes, choose files to commit and write commit messages.
That's all for today!
Now I'm trying to make a character controller able to walk around a small planet (round path).
I will probably talk about it soon, along with our first game design ideas.
You can check the full source for the project setup here: https://bitbucket.org/carniblood/life-in-space/src