IntelliJ Idea 12 + Android + Scala nowadays

13,653

Solution 1

Update: You can read the tutorial I wrote about the upcoming new version of SBT-Android (0.7). Most of your concerns should be addressed there. If they are not, then that's a problem.


Update 2: For fairness's sake, there's also a great work in progress : android-sdk-plugin by @pfn on GitHub.

Regarding ProGuard and build times :

  • I am, myself, preloading large libraries on my device with sbt-android. This eliminates ProGuard altogether, but requires root.

  • android-sdk-plugin's latest version boasts a new ProGuard cache (same as AndroidProguardScala), which is pretty sweet and does eliminate ProGuard in most cases during development.


I've been contributing to SBT-Android for a few months now, so I know it a lot better than the other solutions.

As of now, the plugin is evolving rapidly, with :

  • Full IntelliJ support (thanks to SBTIdea) coming very soon (In fact, it already works, I just need to send the pull requests)
  • Automatically preload Scala on an emulator, or rooted device (Just run android:preload-{device, emulator}, no Proguard needed for development anymore!)
  • Should support simple Gradle projects out-of-the-box with minimal effort (The directory structure is very similar)
  • Configuration is a lot easier (Just add the plugin and a project file and you're set!)

The current version doesn't have most of these niceties, but they're coming up in the following weeks. Some documentation is of course going to follow very soon afterwards, with examples and everything I'll think of.

I encourage you to join the Scala on Android Google Group and share your thoughts, by the way. There's also a #sbt-android channel on Freenode if you're into IRC.

Solution 2

Just wanted to chime in on this. I used https://github.com/yareally/android-scala-intellij-no-sbt-plugin, although I found the instructions to be vague, not having ever used IntelliJ before this.

You've probably got it all sorted out by now and are happy with SBT, but for my purposes I just wanted to test Scala on Android without all the extra bells and whistles. So, here are some little things I had to do to get the no-sbt-plugin stuff working:

I ended up including the scala-compiler.jar (along with the scala-library.jar and scala-reflect.jar) as a Global Library: enter image description here

That way, the compiler has access to the library & reflection code, otherwise I was getting errors. If you don't include the library, the IDE complains that the compiler needs an associated library, and if you don't include reflect it spits out a bunch of errors at compile time that it cannot find reflect class definitions.

I had to include scala-library.jar as a module dependency as well (which had the side effect of including it under the Libraries section also): enter image description here

Before doing all that, I had the Scala plugin installed, created an Android project, and simply added a Scala facet (ignore the memory settings, I was fooling around): enter image description here

Finally, I had to resolve some remaining compilation errors by adding a few "-dontwarn" lines to the proguard txt file. Simple enough.

Works like a charm. Haven't done anything substantial with it yet, but am looking forward to using Scala on my next Android project.

Solution 3

I wrote the Scaloid library that makes Android development more concisely with Scala.

For a quick starting point, I wrote a hello-world maven project for Scala+Android.

I use Intellij as a main IDE, and it imports the project with a charm.

Solution 4

I've gone through this about a month ago and I managed to make it work quite nicely using Gradle.

Here is the outcome: https://github.com/ghik/akkdroid

This is a simple client-server project using Scala and Akka, with client-side on Android, developed with IntelliJ IDEA. I know that client-server doesn't really make sense with Akka, but that's just a simple university project to prove that these technologies can work together.

Note however that gradle script in this project is meant only to generate IDEA project, it has to be further extended to be able to perform proper Android application build.

Solution 5

I have been watching this thread for several months, finally got some time to do the real tests.

Using IntelliJ 13 with SBT 0.13 and Scala 2.10.3.

  1. The SBT-Android hasn't been updated for several months. I found the instructions were outdated and I didn't manage to create a working project.

  2. The android-sdk-plugin worked. Just followed the simple steps and I got "hello world" running on my phone. But importing the SBT project into IntelliJ will not work properly, will need some project modifications manually.

  3. I have also tried to create an Android project first then add Scala framework, but didn't work out as I was expecting.

Share:
13,653
Alan Coromano
Author by

Alan Coromano

Updated on June 07, 2022

Comments

  • Alan Coromano
    Alan Coromano almost 2 years

    As suggested to me, I've run through a few articles describing how to make IntelliJ Idea and Android and Scala work together, but it turned out they were all written 1 or 2 years ago. And likely, something has changed since that time and now there are other solutions to achieve this goal. Concretely, there is a new solution https://github.com/yareally/android-scala-intellij-no-sbt-plugin for which I don't know if it works well or not.

    I have IntelliJ Idea 12, Android SDK, Scala, SBT and all other stuff installed and set up. The only thing remaining is to setup IntelliJ Idea 12 to make it work with Scala instead of Java for creating Android applications.

    Please don't close the question. I saw the previous questions similar to mine, but, as I said, they were outdated.

    The question is, how do I do it now (May 2013)?

    P.S. I tried Android Development Studio but I even wasn't able to launch it due to many errors.

  • Alan Coromano
    Alan Coromano almost 11 years
  • F.X.
    F.X. almost 11 years
    He's just using Proguard, which is what SBT-Android has been doing for quite a long time. So yes, in a way I know what he's doing ;)
  • Alan Coromano
    Alan Coromano almost 11 years
    So do I have to use his solution rather then yours?
  • F.X.
    F.X. almost 11 years
    Well, with SBT-Android you get dependency management, quick command-line builds, preloading (this saves so much time by letting you skip Proguard that you don't want to miss it!) and a bunch of other things. His solution does nothing, so I personally wouldn't recommend it...
  • Alan Coromano
    Alan Coromano almost 11 years
    alright. but isn't his solution much simpler, do I really need all these things that your solution offers?
  • F.X.
    F.X. almost 11 years
    It depends on what you need, of course. Start by trying one and see how it goes for you, and just ask around if you're having trouble. It should be pretty easy to convert his solution to an SBT project if you feel you need it!
  • Alan Coromano
    Alan Coromano almost 11 years
    it seems like it's tricky to setup it. where do I have to start from?
  • F.X.
    F.X. almost 11 years
    See my update, it should set you on the right track. If you're willing to wait for a few weeks, I have a full tutorial planned, covering everything with nice examples and screenshots ;)
  • Alan Coromano
    Alan Coromano almost 11 years
    Would you mind taking a look at stackoverflow.com/questions/16814488/…
  • Alan Coromano
    Alan Coromano almost 11 years
    I'd like it to use sbt, not maven.
  • Srinivas
    Srinivas almost 11 years
    @F.X. I have followed your tutorial, but I am getting errors like org.scala-sbt:sbt-android:0.7-SNAPSHOT I changed plugin version to 0.6.4, then it worked but there are few other errors like error; not found: value androidDefaults, not able to create project by following the tutorial, let me know if I am missing anything.
  • F.X.
    F.X. almost 11 years
    @Srinivas: Did you follow everything above, including cloning my branch? My changes haven't been pushed to master yet, so the main plugin doesn't include some changes presetn in the tutorial.
  • Srinivas
    Srinivas almost 11 years
    @F.X. I literally copied all the instructions from the tutorial under section Creating a project from scratch, sbt is not able to resolve sbt-android-0.7 here is the error, module not found: org.scala-sbt#sbt-android;0.7-SNAPSHOT. Even if choose 0.6.4, still there are more errors like invalid androidDefaults
  • Srinivas
    Srinivas almost 11 years
    @F.X. Thank you, I missed publishing android-plugin locally, after doing that step, I was able to build and install, but there is a runtime exception, java.lang.NoClassDefFoundError: com.scratch.R$layout
  • F.X.
    F.X. almost 11 years
    @Srinivas: Which OS are you running as? Linux? Did you clean before rebuilding? I haven't seen that myself, but it might very well be a bug ;)
  • Srinivas
    Srinivas almost 11 years
    @F.X. I am using Mac OS, yeah I did clean it and tried to rebuild it still no luck. I cloned android-scratch and execute sbt start, I get these kind of NoClassDefFoundError exceptions.
  • F.X.
    F.X. almost 11 years
    @Srinivas: Then it is a bug. I'll look into it!
  • Srinivas
    Srinivas almost 11 years
    @F.X. Is there any way to compile automatically(using command line sbt) whenever there is a change in source code?
  • F.X.
    F.X. almost 11 years
    Sure, just use ~ (tilda) in front of your command, like ~compile ;)
  • Pascal
    Pascal over 10 years
    There seems to be another repo called hello-scaloid-sbt: github.com/pocorall/hello-scaloid-sbt
  • herman
    herman over 10 years
    I think this can be done much simpler by right-clicking the project without Scala facet, choosing Add Framework Support..., then choosing Scala.
  • Incerteza
    Incerteza over 10 years
    what is the easiest way to create a library for Android using Scala and your plugin?
  • Incerteza
    Incerteza over 10 years
    will you take a look at this similar question which is unanswered stackoverflow.com/questions/19688275/scala-library-for-andro‌​id ?
  • Incerteza
    Incerteza about 10 years
    if you don't mind, take a look here stackoverflow.com/questions/23589391/… as I'm confused by the number of different projects for running Scala on Android. And even in yours it's sort of tough to figure out how to do properly.
  • Incerteza
    Incerteza about 10 years
    @Pascal, what does it have to do with Android?
  • Incerteza
    Incerteza about 10 years
    what about Android Studio?
  • ghik
    ghik about 10 years
    @Alex Didn't try, probably not.
  • Pascal
    Pascal about 10 years
    @Alex, as the repository's descriptions says, "[it] is a template project that can be a starting point of a new Scaloid project." Scaloid can be used for Android development.
  • hayesgm
    hayesgm over 9 years
    @MariusKavansky, it supports using SBT as your build tool. I am able to simply run sbt "~ run" and develop from any IDE.
  • Ostkontentitan
    Ostkontentitan about 9 years
    @Alex Android Studio worked perfectly fine for me. :-)
  • Damian Helme
    Damian Helme over 8 years
    @F.X. your tutorial link fxthomas.github.io/android-plugin is giving a 404. Has the page moved?