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:
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
- Install OpenJDK-11-jdk
- `sudo apt install openjdk-11-jdk`
- Install Jetbrains' IntelliJ
- Manually install
- Download from https://www.jetbrains.com/idea/download/
- Create a directory for it: `sudo mkdir -p /opt/jetbrains/intellij/`
- Untar/uncompress to the created directory: `sudo tar -xvf ideaIU-2018.1.3.tar.gz -C /opt/jetbrains/intellij/`
- -x for uncompress, -v for verbose, -f to specify file, -C to specify output directory
- To run intellij: `nohup /opt/jetbrains/intellij/idea-IU-181.4892.42/bin/idea.sh &`
- NOTE: Your build version may change which would change the directory name.
- `nohup` will disconnect the process from the bash instance, so it can be closed.
- Snap install
- NOTE: Snap install will make an icon available from the desktop launcher, which is nice.
- From a terminal: sudo snap install intellij-idea-ultimate --classic --edge
- or sudo snap install intellij-idea-community --classic --edge
- Download the project starter from the libgdx website: https://libgdx.badlogicgames.com/download.html
- Version as of this writing is the nightly build from 2018 May 15th with MD5 of 1b2279840af26946e346fe913cd48b93
- Download Android SDK
- Launch IntelliJ
- Navigate to Android SDK Options:
- From initial screen: Configuration->Settings->Appearance & Behavior->System Settings->Android SDK
- From Open project: File->Settings->Appearance & Behavior->System Settings->Android SDK
- On right side of Android SDK Location input field select `Edit`
- Follow prompts for SDK Manager that follow.
- 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.
- Create directory for your project
- `mkdir -p ~/IdeaProjects/TestGame`
- Run the gdx-setup.jar with `java -jar ~/Downloads/gdx-setup.jar`
- Enter Name: `TestGame`
- Enter Package: `com.yourdomain.testgame`
- NOTE: Must be all lowercase to be valid
- GameClass: `TestGame`
- Destination: `~/IdeaProjects/TestGame`
- 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"]
- Deselect: Html
- Select: Third party libraries and extensions as needed.
- Open Advanced:
- Select Kotlin
- Select IDEA
- Select Generate
- NOTE: In my setup this reported a build failure. We will fix that next.
- Close gdx-setup.jar, got to terminal and navigate to your project directory
- `cd ~/IdeaProjects/TestGame`
- Try a build, it should fail for the same reason as gdx-setup complained about.
- `gradle build`
- Update `build.gradle` to upgrade the Kotlin version
- Use your favorite editor to change line #2 from version 1.1.1 to 1.2.41
- 1.2.41 is newest at time of this writing.
- Try build again: `gradle build`
- Get a fail for missing `:android:lintClassPath`
- Update root build.gradle
- Add `jcenter()` repository to `allprojects{ repositories {...` section.
- Try build again: `gradle build`
- Get a fail for AndroidSdkHandler
- Update build.gradle
- Change: classpath 'com.android.tools.build:gradle:3.1.0' to classpath 'com.android.tools.build:gradle:gradle:3.2.0-alpha14'
- Other versions may work as well. Didn't research why 3.1.0 was causing failures.
- Older versions caused the AndroidSdkHandler error referenced at the end of this document.
- Try build again. This time it works!
- Import project into Intellij
- Start Intellij
- Import Project->Navigate to and select the root build.gradle for the project.
- "Import Project From Gradle" window:
- De-Select->"Create separate module per source set"
- Edit Run/Debug Configurations
- Select "Edit Configurations" from dropdown at top right of window.
- Add a configuration using + at top left of modal
- Select Application
- Name it "Desktop" (or whatever seems good to you)
- Main class: Select DesktopLauncher
- If it doesn't prepopulate, try a NEWER version of the JDK.
- Oracle JDK 8 caused a "DesktopLauncher is not acceptable" modal for my setup. OpenJDK-11-JDK worked.
- NOTE Probably should exit IntelliJ while changing JDK as it is a java program as well.
- Working Directory: ....TestGame/android/assets
- Yes, use the android assets
- This tip came from https://youtu.be/foqd4l0GKOw?t=9m49s
- Big thanks to his video, it was a big help. It also walks through downloading the Android SDK.
- Use Classpath of module: Desktop
- Apply/Ok
- Try running desktop using green arrow in top right of IntelliJ.
- Should get a red background with bad logic picture in bottom left.
- Create a configuration for Android
- Edit run/debug configurations
- Add Android
- Module: android
- Target: Emulator
- Prefer Android Virtual Device: <Create one>
- Start writing code.
ERRORS:
KVM permission denied
- Turn on SMT/KVM in your Bios
- Follow these instructions: https://developer.android.com/studio/run/emulator-acceleration#vm-linux
- In Ubuntu 18.04 `ia32-libs-multiarch` is not found, but that didn't seem to stop my setup from working
- `sudo apt install qemu-kvm libvirt-bin ubuntu-vm-builder bridge-utils`
- Add your user to the kvm group which owns /dev/kvm
- `sudo adduser "$(whoami)" kvm` <-- This script will automatically insert your current user.
- Log out/Log in.
- Required to make addition to new group take effect.
DesktopLauncher is not acceptable
- Fix that worked:
- Close IntelliJ
- Remove Oracle-JDK-8, add OpenJDK-11-JDK.
- `sudo apt remove oracle-jdk-*`
- `sudo apt install openjdk-11-jdk`
- Update $JAVA_HOME to point to the openJDK
- NOTE: I never did figure out where Oracle set the $JAVA_HOME but it wasn't /etc/profile or ~/.bashrc.
- add `export JAVA_HOME=/usr/lib/jvm/java-11-openjdk-amd64/` to your ~/.bashrc
- Consider adding it to /etc/profile.
- Open IntelliJ and try adding the Run/Debug configuration again
Could not resolve all files for configuration ':android:lintClassPath'
- 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;
- Workaround that fixed it:
- 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
- Seems to be caused by JDK mismatches on the same system:
- Workaround that fixed it:
- Update project `build.gradle` with:
- `buildscript {
//other stuff
dependencies {
classpath 'com.android.tools.build:gradle:3.2.0-alpha14'`
}
}` - Try #1:
- Make system default to a specific JDK
- `sudo update-alternatives --config java`
- `sudo update-alternatives --config javac`
- Try #2:
- Remove all but one JDK
- `sudo apt remove <other jdk>`
Thank you for your help! I've been trying hours how to fix "Failed to notify project evaluation listener"
ReplyDelete