libgdx && android && scala && idea
29 Sep 2014I would like to seriously start learning Scala… So why not try it out to do some Android development? To make it even more funny (… or tragic) lets mix in the libgdx library. I installed Scala and SBT plugins for IntelliJ and started with this description for project setup. Everything works perfectly fine when running:
curl https://raw.github.com/n8han/conscript/master/setup.sh | sh
cs n8han/giter8
g8 ajhager/libgdx-sbt-project
… but the second IntelliJ tries to open the project (or you want to build it with sbt
) - bang! - a surprise:
java.lang.RuntimeException: set ANDROID_HOME or run 'android update project -p /home/user/Projects/colors/android'
at scala.sys.package$.error(package.scala:27)
at android.Plugin$$anonfun$allPluginSettings$67$$anonfun$apply$28.apply(rules.scala:350)
at android.Plugin$$anonfun$allPluginSettings$67$$anonfun$apply$28.apply(rules.scala:350)
at scala.Option.getOrElse(Option.scala:120)
at android.Plugin$$anonfun$allPluginSettings$67.apply(rules.scala:350)
at android.Plugin$$anonfun$allPluginSettings$67.apply(rules.scala:342)
at scala.Function2$$anonfun$tupled$1.apply(Function2.scala:54)
at scala.Function2$$anonfun$tupled$1.apply(Function2.scala:53)
at scala.Function1$$anonfun$compose$1.apply(Function1.scala:47)
at sbt.EvaluateSettings$MixedNode.evaluate0(INode.scala:177)
at sbt.EvaluateSettings$INode.evaluate(INode.scala:135)
at sbt.EvaluateSettings$$anonfun$sbt$EvaluateSettings$$submitEvaluate$1.apply$mcV$sp(INode.scala:67)
at sbt.EvaluateSettings.sbt$EvaluateSettings$$run0(INode.scala:76)
at sbt.EvaluateSettings$$anon$3.run(INode.scala:72)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:745)
[error] set ANDROID_HOME or run 'android update project -p /home/koperek/Projects/colors/android'
[error] Use 'last' for the full log.
Project loading failed: (r)etry, (q)uit, (l)ast, or (i)gnore?
So how to bootstrap a working libgdx@scala project?
- Install conscript and g8 (first two lines of snippet above).
- Define
ANDROID_HOME
inidea.sh
and.bashrc
- Use my fork of libgdx template:
g8 pkoperek/libgdx-sbt-project
- Run
sbt "project core" gen-idea
- Open the project in IntelliJ (not import - this doesn’t work - open)
- After opening in IDEA:
- In
android
module settings set the language level to6.0
. - In
desktop
module settings removenull
from source roots list. - Unmark
gen/com
as source root.
Fork of template contains following improvements:
- Fixes project layout (
src/main/scala
instead ofsrc
) - Removes test code from APKs (you can add test dependencies to
test
scope instead of compile + removing by proguard) - Updated plugins and libgdx versions
- Adds
scalatest
- Adds
sbt-idea
plugin in latest version
Workflow:
- After adding a new dependency remember about
sbt update
andsbt "project core" gen-idea
- To run app in emulator, start one with AVD and run
sbt android/android:run
- To generate a package hit
sbt android/android:package