Tuesday, July 24, 2012

scalaz for the Eclipse Scala IDE plugin

There's a brand new build of scalaz 6.0.4 for M5 that seems to work well with the Eclipse plugin.  If you were having issues before with scalaz + Eclipse, give this one a shot:


Saturday, July 14, 2012

Scala on Android: what you need to know (some of this applies to any large Android codebase)

Here's a collection of all of the interesting links talking about issues with Scala running on Android.  (And note that it's not specific to Scala; it's large codebases generally.)


Android tools limit you to 65535 methods referenced, which includes both methods defined and methods called.  If you hit this limit (and you will with anything past hello-world when you're using the Scala library), you need to run an external tool.

If you use Eclipse, try my AndroidProguardScala plugin.

If you use sbt, use the sbt Android plugin.

Useful links

http://code.google.com/p/android/issues/detail?id=7147 Issue 7147: dx fails on scala-library.jar and scala-compiler.jar
The Android bug.  Important quote:
It turns out that you have made the first report we've seen of anyone running into Dalvik's existing limit of 
65536 method references per dex file
https://issues.scala-lang.org/browse/SI-5278 Scala outputs redundant interface declarations in bytecode
This is the bug + fix that should solve LinnearAlloc issues.

http://code.google.com/p/android/issues/detail?id=22586 Issue 22586: Dexopt fails with "LinearAlloc exceeded" for deep interface hierarchies
Earlier Scala versions hit this, but the problem has been solved by SI-5278.

https://issues.scala-lang.org/browse/SI-4620 Android install of scala 2.9.0 built binary fails (worked with scala 2.8.1)
Here's the Scala issue covering the Scala patch that reduced the

https://github.com/scala/scala/commit/7a99c03da1d31ac5950eecb30f422f43c5e3d04e Don't generate redundant interfaces
Here's the Scala patch itself.  It includes this comment:
Drop redundant interfaces (ones which are implemented by some
other parent) from the immediate parents. This is important on
android because there is otherwise an interface explosion.
http://code.google.com/p/android/issues/detail?id=20814 dx crashes on projects with > 65,535 methods
Note that the title is misleading (it's not just number of methods).  From the bug:
As I understand it, the limit is the number of methods referenced, which includes both methods defined and methods called, which is why you might see this even if your app only contains 56,484 method definitions.
A conversation about using Scala with Android

Thursday, July 12, 2012

Getting this? E/dalvikvm( 6037): JNI ERROR (app bug): attempt to use stale weak global reference 0xb

Seeing this in your Android code?

E/dalvikvm( 6037): JNI ERROR (app bug): attempt to use stale weak global reference 0xb

Make sure you're not:

a) Calling back into java from javascript in a WebView, and then b) Dereferencing a null pointer in Java.

Notice that this problem has nothing to do with any of your JNI code.

Thursday, July 5, 2012

Parsing Java signatures with Scala's parser combinators

I need to parse some Java signatures for a new version of the AndroidProguardScala plugin. I had read about #Scala parser combinators, but never used them. Here's what I came up with for parsing Java signatures (the things like Ljava/util/List<[Ljava/util/List<Ljava/lang/String;>;>; that you see when you're using asm and other tools).

And here's the test file:

New version of the Android/Scala Eclipse plugin available

I released a new version (41) of the AndroidProguardScala Eclipse plugin making it easier to run #Scala code on #Android. This one fixes a few bugs and should work nicely with the latest ADT. Available here.

Using maven just to fetch dependencies, not to build

There are lots of useful things about maven, but I needed to just fetch some dependencies. Here's how:

Run mvn dependency:copy-dependencies and you'll end up with your dependencies in your ./libs directory.