Some Background Information
I am in the process of writing a programming tutorial series about billiards. It will use Java as the language, Android Studios as the IDE, and libgdx as the supporting framework.
Also, if you have already setup LibGDX for Android Studio? Head on over to my newest tutorial about custom bitmap fonts. In it, you will learn how to make fonts that can be used in your android apps.
What is Android Studio?
Android studio is an IDE for Android developers. First announced earlier 2013, it has since grown to be a very effective tool. Last month, June 2014, Android Studio has went from alpha to beta. If you wish not to use an ‘in progress’ IDE, your other option is Eclipse. But hey, out with the old and in with the new. Source: http://en.wikipedia.org/wiki/Android_Studio
Unlike Eclipse, Android Studio is, in my own opinion:
- Visually unified
- More productive
What is libGDX?
I like to call it a convenience. It is like XNA game studios for Android developers. It integrates easily into Android Studio, is cross-platform, and is super-fast. For a full detailed list, visit their feature page http://libgdx.badlogicgames.com/features.html
How to install Android Studio Beta
If you do not have Android Studio installed, you should do some research into it. I suggest going to the android developer homepage. https://developer.android.com/index.html. I will not go into great detail about this. Also,make sure to read the Terms and Conditions of anything you use. It is your obligation. Without doing so, you never know what you are getting into.
Download and install Android Studios Beta.
Download and install the Java Development Kit.
After everything is finished, open the Android SDK Manager and add the packages that you need. My Suggestions:
- Install the packages it wants you to install by default
- Install all Android SDK Build-tools installed
- Install the SDK Platform and SDK Sources for each android (API Lv.) Installed
4. Go to File>Settings. Under the Appearances tab, select Darcula Theme and Hit OK.
How to correctly setup libGDX
It took me three days to figure this out. I am letting you do it in one day.
Go to the libGDX download page and download the setup app. This file will generate an Android Studio Project with all the necessary libgdx libraries and cross-platform modules for you. http://libgdx.badlogicgames.com/download.html
- Click on the download file and save it to your computer.
- Open the jar file. Then, fill in the dialog box as follows:
- Leave Name: unchanged
- Leave Package: unchanged.
- Leave GameClass: unchanged
- Go to your \AndroidStudioProjects Folder in the Library Explorer and create a new folder called \SetupGame. This is where our new project will be generated.
- Change Destination to:
- Change AndroidSDK to:
- Leave all Sub Projects: checked
- Uncheck the Box2d Extension unless you know you are going to use it.
- Click Generate:
4. From the Android Studio welcome screen, click Import Project and select: C:\Users\<USER_NAME>\AndroidStudioProjects\SetupGame\build.gradld. This is going to open up the project for us.
5. DO NOT PANIC. You will get this screen saying there is an error. This is easy to fix.
6. In your Library Explorer,
- Navigate to C:\Users\<USER_NAME>\AndroidStudioProjects\SetupGame.
- Right click on the .idea folder
- Delete It.
Thank you Drasco Saric for adding this one step. You are the best. https://plus.google.com/+DraskoSaric/posts/7YzcE6YpfwK
7. Back in Android Studio. Press (Ctrl+Alt+Y) to synchronize your project. A new .idea folder will be auto-generated with the correct contents. Honestly, I do not know why it does this. I just know that it works.
8. Double tap on any of the file breadcrumb tabs to open up the project file viewer screen.
9. Now open up your MySetupGame/build.gradle file and make one small change.
Change: classpath ‘com.android.tools.build:gradle:0.10+’ to …0.12+’
10. Sync your project again
If you do not get any errors, this is a success. you now have now setup libgdx for Android Studio.
Post Android Studio Setup
Now that you have your project correctly setup, here are a few things you should do.
Copy and Paste your SetupGame Project somewhere as a backup.
If you want to change the package name, right-click on it and select Refactor>Rename.
To build your project, I highly suggest that you use a real android device, not an emulator. This is because they are really slow. Here is how to access the developer options on your phone.
1. Go the phone settings, scroll to the bottom, tap About Phone, scroll to the bottom, and tap the Build Number until it says that you are already a developer
Now in your settings, go to developer options and turn them on. Also make sure to enable USB Debugging. In Android Studio, run the program and select the connected device. You might be asked for permission to do so. BOOM! This is what you should see:
If you want to build your project on other platforms, just follow these simple steps outlined on the wiki https://github.com/libgdx/libgdx/wiki/Gradle-and-Intellij-IDEA
That is it!
If you followed this post to the very end. Congratulations. If you have any questions comments or concerns, feel free to leave them in the comments below. Happy Coding. Enjoy!
UPDATE: …/gradle2.0-all.zip Error (SOLVED)
So I recently generated a
new project and a new error occured. It says somthing along the lines of:
“../gradle1.10-all requried, try changing ../gradle2.0-all in destination ulr”
Go to /gradle/wrapper/gradle-wrapper-properties
Change: the distributionUrl to
Sync You project, it should take about 5 min. to fix. At least that is what it did for me.