Scala is a functional, object-oriented programming language for the JVM that works seamlessly with Java libraries, frameworks, and tools. It has a concise syntax and a REPL, which makes it feel like a scripting language, but it is being used in mission critical server software at companies like Twitter and LinkedIn. Scala developers usually choose either Gradle or SBT as their build tool. This tutorial shows how to set up either of them to start using LibGDX. You may choose which one to use according to your own preferences. Due to how GWT works you will not be able to use the HTML5 target with Scala

Using libGDX and Scala with Gradle

gdx-scala-demo. These changes have been outlined below. In order to support Scala compilation you need to update the build with a couple of additions:

  • -
    • project(":core") section: apply plugin: "scala"
  • compile "org.scala-lang:scala-library:2.11.12" (Scala 2.12.* requires java 8, but the majority of Android devices don’t support it)
  • -
  • optional Set the src directory for scala files: sourceSets.main.scala.srcDirs = [ "src/" ]
  • /android/build.gradle

  • android section (top of the file) you need to add the following:

  1. lintOptions { abortOnError false // make sure you're paying attention to the linter output!}// FIXME: How can we apply this simply for all builds? Copy-pasta makes me sad.buildTypes { release { minifyEnabled true proguardFile getDefaultProguardFile('proguard-android-optimize.txt') proguardFile 'proguard-project.txt' } debug { minifyEnabled true proguardFile getDefaultProguardFile('proguard-android-optimize.txt') proguardFile 'proguard-project.txt' }}
  • /android/proguard-project.txt

  • In order for Proguard to work you need to add the following lines:

  1. -dontwarn sun.misc.*-dontwarn java.lang.management.**-dontwarn java.beans.**
  • -dontwarn com.badlogic.gdx.jnigen.BuildTarget* to -dontwarn com.badlogic.gdx.jnigen.* With all of these changes in-place you should be able to use Gradle exactly as you would otherwise from the shell or your favorite IDE.

    Using libGDX and Scala with SBT

    libgdx-sbt-project, that provides a simple path for getting started with libGDX and Scala using standard build tools and best practices. sbt 0.13, which are used in the Scala community for generating and interacting with projects.

    Setting up a new project

    In your favourite shell type:
    1. $ sbt new ajhager/libgdx-sbt-project.g8
    After filling in some information about your project, you can start placing your game’s source files and assets in common/src/main/scala and common/src/main/resources, respectively. NOTICE The setup above might not be working with iOS build. If you want to use MobiDevelop’s fork of RoboVM, then one should use
  1. fork of sbt-robovm, you need sbt publish-local this plugin yourself for now.
  2. fork of project template and use sbt-robovm and RoboVM version 2.3.0. Then it will resolve to the plugin that get publish-localed

    Managing your project

    Update to the latest libraries:
    1. $ sbt> update
    Run the desktop project:
    1. > desktop/run
    Package the desktop project into single jar:
    1. > assembly
    Run the android project on a device:
    1. > android/start
    android-plugin for a more in-depth guide to android configuration and usage. Run the ios project on a device:
    1. > ios/device
    sbt-robovm for a more in-depth guide to ios configuration and usage.

    Using unit tests

    Run all unit tests from desktop, android and common (subdirectories src/test/scala):
    1. > test
    Run specific set of unit tests:
    1. > common/test
    In most cases you will be able to open and edit each sub-project (like common, android or desktop), but you still need to use SBT to build the project. here for details about sbt plugins for each editor.

    Other resources

    Develop Games in Scala with libgdx