Skip to main content

Initial Project Setup with LibGDX (1.9.8)

Today started with the idea of spending a few hours trying out libgdx (https://libgdx.badlogicgames.com/). The website looks nice, they have nightly builds of configuration tools and plenty of documentation. I got started by downloading `gdx-setup.jar` and running it. However it took the next 3 hours trudging through a path of dependency, JDK version and other issues before I got anything running. I've put the final build.gradle file here: Project Root [ build.gradle ] as well as the final TempGame/android/build.gradle here: android subproject [ build.gradle ]. The log of what it took to get it running is below, I apologize in advance for the wall of ugly text, but it was a running log as I fixed things. There is an ERRORS section below it that may offer some help if you've found yourself here after a google search and don't want to use the final build.gradle or follow from the beginning.

I figured I'd take the time to write up the steps I finally followed to get a working build.
My development machine setup:

  • Ryzen 2700x
  • 16Gb DDR4
  • Ubuntu 18.04
    • OpenJDK-11-jdk [after several version changes]
    • Jetbrains IntelliJ 2018.1.3
      • NOTE: Android studio 3.1 can also be used.
High Level Project Setup:
  • Use Kotlin and IntelliJ
  • Build for Desktop and Android
  1. Install OpenJDK-11-jdk
    1. `sudo apt install openjdk-11-jdk`
  2. Install Jetbrains' IntelliJ
    1. Manually install
      1. Download from https://www.jetbrains.com/idea/download/
      2. Create a directory for it: `sudo mkdir -p /opt/jetbrains/intellij/`
      3. Untar/uncompress to the created directory: `sudo tar -xvf ideaIU-2018.1.3.tar.gz -C /opt/jetbrains/intellij/`
        1. -x for uncompress, -v for verbose, -f to specify file, -C to specify output directory
      4. To run intellij: `nohup /opt/jetbrains/intellij/idea-IU-181.4892.42/bin/idea.sh &`
        1. NOTE: Your build version may change which would change the directory name.
        2. `nohup` will disconnect the process from the bash instance, so it can be closed.
    2. Snap install
      1. NOTE: Snap install will make an icon available from the desktop launcher, which is nice.
      2. From a terminal: sudo snap install intellij-idea-ultimate --classic --edge
        1. or sudo snap install intellij-idea-community --classic --edge
  3. Download the project starter from the libgdx website: https://libgdx.badlogicgames.com/download.html
    1. Version as of this writing is the nightly build from 2018 May 15th with MD5 of 1b2279840af26946e346fe913cd48b93
  4. Download Android SDK
    1. Launch IntelliJ
    2. Navigate to Android SDK Options:
      1. From initial screen: Configuration->Settings->Appearance & Behavior->System Settings->Android SDK
      2. From Open project: File->Settings->Appearance & Behavior->System Settings->Android SDK
    3. On right side of Android SDK Location input field select `Edit`
    4. Follow prompts for SDK Manager that follow.
      1. NOTE: I noticed that the detailed view of progress during download shows a constantly scrolling text of current URL being downloaded. This is a bug, however the process DID complete for me, just had to be patient.
  5. Create directory for your project
    1. `mkdir -p ~/IdeaProjects/TestGame`
  6. Run the gdx-setup.jar with `java -jar ~/Downloads/gdx-setup.jar`
    1. Enter Name: `TestGame`
    2. Enter Package: `com.yourdomain.testgame`
      1. NOTE: Must be all lowercase to be valid
    3. GameClass: `TestGame`
    4. Destination: `~/IdeaProjects/TestGame`
    5. AndroidSDK: Should already have been detected unless you moved the default install directory. If you did, point it at that custom location. [Default: "~/Android/Sdk"]
    6. Deselect: Html
    7. Select: Third party libraries and extensions as needed.
    8. Open Advanced:
      1. Select Kotlin
      2. Select IDEA
    9. Select Generate
      1. NOTE: In my setup this reported a build failure. We will fix that next.
  7. Close gdx-setup.jar, got to terminal and navigate to your project directory
    1. `cd ~/IdeaProjects/TestGame`
  8. Try a build, it should fail for the same reason as gdx-setup complained about.
    1. `gradle build`
  9. Update `build.gradle` to upgrade the Kotlin version
    1. Use your favorite editor to change line #2 from version 1.1.1 to 1.2.41
      1. 1.2.41 is newest at time of this writing.
  10. Try build again: `gradle build`
    1. Get a fail for missing `:android:lintClassPath`
  11. Update root build.gradle
    1.  Add `jcenter()` repository to `allprojects{ repositories {...` section.
  12. Try build again: `gradle build`
    1. Get a fail for AndroidSdkHandler
  13. Update build.gradle
    1. Change: classpath 'com.android.tools.build:gradle:3.1.0' to classpath 'com.android.tools.build:gradle:gradle:3.2.0-alpha14'
      1. Other versions may work as well. Didn't research why 3.1.0 was causing failures.
      2. Older versions caused the AndroidSdkHandler error referenced at the end of this document.
  14. Try build again. This time it works!
  15. Import project into Intellij
    1. Start Intellij
    2. Import Project->Navigate to and select the root build.gradle for the project.
    3. "Import Project From Gradle" window:
      1. De-Select->"Create separate module per source set"
    4. Edit Run/Debug Configurations
      1. Select "Edit Configurations" from dropdown at top right of window.
      2. Add a configuration using + at top left of modal
        1. Select Application
        2. Name it "Desktop" (or whatever seems good to you)
        3. Main class: Select DesktopLauncher
          1. If it doesn't prepopulate, try a NEWER version of the JDK.
            1. Oracle JDK 8 caused a "DesktopLauncher is not acceptable" modal for my setup. OpenJDK-11-JDK worked.
            2. NOTE Probably should exit IntelliJ while changing JDK as it is a java program as well.
        4. Working Directory: ....TestGame/android/assets
          1. Yes, use the android assets
          2. This tip came from https://youtu.be/foqd4l0GKOw?t=9m49s

            1. Big thanks to his video, it was a big help. It also walks through downloading the Android SDK.
        5. Use Classpath of module: Desktop
        6. Apply/Ok
  16. Try running desktop using green arrow in top right of IntelliJ.
    1. Should get a red background with bad logic picture in bottom left.
  17. Create a configuration for Android
    1. Edit run/debug configurations
    2. Add Android
      1. Module: android
      2. Target: Emulator
        1. Prefer Android Virtual Device: <Create one>
  18. Start writing code.

ERRORS:

KVM permission denied

    1. Turn on SMT/KVM in your Bios
    2. Follow these instructions: https://developer.android.com/studio/run/emulator-acceleration#vm-linux
      1. In Ubuntu 18.04 `ia32-libs-multiarch` is not found, but that didn't seem to stop my setup from working
        1. `sudo apt install qemu-kvm libvirt-bin ubuntu-vm-builder bridge-utils`
    3. Add your user to the kvm group which owns /dev/kvm
      1. `sudo adduser "$(whoami)" kvm` <-- This script will automatically insert your current user.
    4. Log out/Log in.
      1. Required to make addition to new group take effect.

DesktopLauncher is not acceptable

    1. Fix that worked:
      1. Close IntelliJ
      2. Remove Oracle-JDK-8, add OpenJDK-11-JDK.
        1. `sudo apt remove oracle-jdk-*`
        2. `sudo apt install openjdk-11-jdk`
      3. Update $JAVA_HOME to point to the openJDK
        1. NOTE: I never did figure out where Oracle set the $JAVA_HOME but it wasn't /etc/profile or ~/.bashrc.
        2. add `export JAVA_HOME=/usr/lib/jvm/java-11-openjdk-amd64/` to your ~/.bashrc
        3. Consider adding it to /etc/profile.
      4. Open IntelliJ and try adding the Run/Debug configuration again

Could not resolve all files for configuration ':android:lintClassPath'

    1. Add `jcenter()` repository to `allprojects{ repositories {...` section of project root build.gradle section.

gdx-setup.jar --> "* What went wrong:A problem occurred configuring project ':android'.> Failed to notify project evaluation listener.   >com.android.build.gradle.internal.variant.BaseVariantData.getOutputs()Ljava/util/List;

    1. Workaround that fixed it:
      1. Update kotlin version in root gradle.build from version 1.1.1 to 1.2.41.

Could not initialize class com.android.sdklib.repository.AndroidSdkHandler

    1. Seems to be caused by JDK mismatches on the same system:
    2. Workaround that fixed it:
      1. Update project `build.gradle` with:
        1. `buildscript {
              //other stuff
              dependencies {
                  classpath 'com.android.tools.build:gradle:3.2.0-alpha14'`
              }
          }`
    3. Try #1:
      1. Make system default to a specific JDK
      2. `sudo update-alternatives --config java`
      3. `sudo update-alternatives --config javac`
    4. Try #2:
      1. Remove all but one JDK
      2. `sudo apt remove <other jdk>`

Comments

  1. Thank you for your help! I've been trying hours how to fix "Failed to notify project evaluation listener"

    ReplyDelete

Post a Comment