Skip to content

salvadordiaz/android-scala-intellij-no-sbt-plugin

 
 

Repository files navigation

Want to use Scala on Android with Intellij without having to resort to additional plugins or losing any awesome Intellij features? 

Before you had to use something like this with sbt and build externally:

https://github.com/jberkel/android-plugin (props to the maintainers/creators, but there's an easier way!)

Just do the following instead:


Testing Scala features on Android (and also building without any additional plugins).

Using proguard lets you build Scala without any extra plugins and sbt fiddling. Shockingly, I never actually saw anyone attempt to try this, but glad I did. Maybe it's because people assume nothing can be that easy when it comes to java related tools :p. This has the benefit of still being compiled with the intellij build system, yay.

FAQ:

Q: What works? 

A:Everything as far as I can tell (even debugging)
--
Q: What doesn't work?

A: Nothing as far as I know so far.
--
Q: What version of Scala did you test with?

A: 2.10.1, the latest stable as of 2013-05-19
--
Q: How is debugging possible?

A: Proguard is set not to obfusticate so it doesn't remove the debugging symbols. That's really the key to my guide.
--
Q: Why does Proguard work?

A: There's way too many methods in Scala for the dalvik compiler (dx) to handle if you simply add all the jars to the class path and compile. Proguard will strip out all the excess (otherwise, you'll get errors like Android Dex: [android-scala] trouble writing output: Too many methods: 66095; max is 65536.).
--
Q: Does Google's Android Studio work, since it's based on Intellij?

A: I don't know as I don't use it normally. Google removed many of the Intellij plugins from the default repository in Android Studio. You may be able to import the Scala plugin though. Since Android Studio is unstable (and nearly identical to Intellij 13 preview), Intellij is the preferred solution, imho.
---

To build in Intellij:

Prerequisites:

1) Get Scala (http://www.scala-lang.org/). If you don't have the Scala plugin for Intellij, you need that too of course.

2) Add a Scala facet to the project, setting up the compiler. You may have to create a separate throwaway Scala module first if no Scala plugin has already been added globally. More directions located here: http://confluence.jetbrains.com/display/SCA/Setting+up+Scala+plugin+project+in+IntelliJ+IDEA (note that scala compiler is now its own section and not under compiler as of IDEA 12.1)

3) Set up the Scala facet for the Android project (add continuations if you wish). Alternatively, setting up a Scala project and then adding an Android Facet might be easier for some.

4) Add the following jars as libraries to the project (or globally):
    continuations.jar (if you want to use them)
    scala-actors.jar
    scala-library.jar

5) Make sure the library is also set as a dependency for all modules you use Scala with.

Compiling your Project:

1) Use the given proguard file in this project

2) Change any references to com.example.android_scala to your package

3) Change any references to com.example.android_scala.MyActivity to your Main Activity

4) Add all jar references to your proguard file pointing to your scala and other libraries. Probably not needed though if you did step #4 correctly under prerequisites.

5) Enable proguard for the building of the project via the following :
Go to: file → project settings → modules → select module(s) → compiler tab → enable proguard

6) Build project like normal

7) Run the application

About

Directions on how to create a Scala based project in Intellij IDEA without having to resort to additional plugins or external building that cripples the nice features of the IDE.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published