Taylor's Blog

Atypical ramblings

Android SDK for IntelliJ IDEA

This morning I’ve been attempting to get LibGDX working with the IntelliJ IDEA IDE as described in this tutorial. However, I quickly ran into a problem. In the instructions it says the following:

Install the latest stable platform via the SDK Manager.

Sounds all well and good, but imagine my surprise when I find out that Google removed the SDK Manager GUI which is really confusing since every tutorial on the web still instructs you to use it. After some poking around, I discovered that you can either download Android Studio (which I’d rather not since it takes up a lot of space) or download the Android Command Line Tools. Problem solved? Well, not quite. Once again, I ran into some inconsistencies with documentation that was available and how the tools actually responded. Everyone online mentions how you need to use the android command in the command line to install packages, but in fact this command has been deprecated. Now we need to use the sdkmanager command instead.

Ok then, well according to the sdkmanager documentation, I just need to run sdkmanager.bat --list to see all available packages right? Wrong! According to this StackOverflow thread, you’ll get an error where the sdkmanager can’t move away the tools folder. So instead you need to follow user ahasbini’s advice:

copy the tools folder to another place (let’s say C:\temp\). Then direct into the C:\temp\tools\bin\, open the cmd prompt there and run your update commands as such:

sdkmanager.bat --sdk_root=sdkRootPath --command

Where sdkRootPath is path to your original SDK folder (C:\testinstall\sdk\). Once that is done, delete the C:\temp\tools\ copied folder.

Yeesh. What a bunch of work for something that should have been so simple! I feel that Google had only left the SDK Manager GUI intact, we wouldn’t have to go through all of this!

Well, anyway, here’s what I had to do to get the the thing working:

  1. I installed a some Android packages using the following commands (not sure if all of them are necessary):
    sdkmanager.bat --sdk_root=C:\testinstall\sdk\ "platforms;android-25"
    sdkmanager.bat --sdk_root=C:\testinstall\sdk\ "sources;android-25"
    sdkmanager.bat --sdk_root=C:\testinstall\sdk\ "build-tools;25.0.3"
    sdkmanager.bat --sdk_root=C:\testinstall\sdk\ "tools"
  2. I followed the instructions on this page to generate a LibGDX project, which consisted of (a) downloading the LibGDX Project setup tool “gdx-setup.jar”, (b) running java -jar ./gdx-setup.jar in the download folder (c) setting up the project as indicated and making sure to go to “advanced” and check the IntelliJ box.
  3. Next, I had to import the LibGDX project into IntelliJ. For that, I followed the steps on this page. I went to Import Project, navigated to my project folder and selected the build.gradle file. I Hit OK and in the next dialog, I unchecked the Create separate module per source set box and hit OK again. A final window will appeared asking which modules to import. I left everything checked and clicked OK.
  4. Now that the project was imported (finally!), I wanted to make sure it would run correctly. I continued with the notes on that page and followed their instructions:

    (a) Go to Run -> Edit Configurations...
    (b) Click the plus (+) button and select Application
    (c) Set the Name to Desktop
    (d) Set the field Use classpath of module to desktop
    (e) Click on the button of the Main class field and select the DesktopLauncher class
    (f) Set the Working directory to your android/assets/ (or your_project_path/core/assets/) folder
    (g) Click Apply and then OK.

  5. Now, I was planning on running this through the web browser as mentioned in the html section of this page, but I my localhost:8080 port is in use at the moment and causes conflicts if I try to use it for LibGDX. So instead, I decided to compile the program as an executable .jar file instead. To do so, I followed the Packaging for the Desktop instructions on this page – In the IntelliJ command line I typed gradlew desktop:dist and a .jar file containing all the necessary code and assets from the android/assets folder was created in my project’s desktop/build/libs folder.
  6. Lastly, I navigated to the .jar and ran the following in the command line to run it:  java-jar desktop-1.0.jar and voila, the “game” came to life! (Double-clicking it also works)
    Phew! It was a lot of work to get working, but now I have the basic layout setup so I can actually start developing some stuff with this. Pretty exciting!
Updated: May 15, 2017 — 5:01 pm

Leave a Reply

Your email address will not be published. Required fields are marked *

Taylor's Blog © 2015