Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IntelliJ Idea 12 + Android + Scala nowadays

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.

like image 278
Alan Coromano Avatar asked May 25 '13 14:05

Alan Coromano


People also ask

Is IntelliJ IDEA good for Android development?

IntelliJ IDEA supports development for multiple platforms, but is missing some of the specialized features included in Android Studio, such as APK support. Android Studio may be a better choice for businesses that develop primarily Android Applications.

Can I use IntelliJ IDEA instead of Android Studio?

No. Android Studio is focused specifically on Android development and provides streamlined environment and project setup, but otherwise all of its features are available in IntelliJ IDEA.

Is IntelliJ IDEA faster than Android Studio?

TL;DR: Android Studio (3.0 version and after) takes a lot of RAM and it's lagging, IntelliJ IDEA is way faster.


2 Answers

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.

like image 146
F.X. Avatar answered Oct 02 '22 13:10

F.X.


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.

like image 27
drhr Avatar answered Oct 02 '22 12:10

drhr