jberkel / android-plugin

An sbt plugin for Android development in Scala
https://groups.google.com/forum/#!forum/scala-on-android
Other
476 stars 113 forks source link

Default settings lead to java.lang.NoClassDefFoundError: ....R$layout #136

Open scvalex opened 12 years ago

scvalex commented 12 years ago

Using Scala 2.9.2, sbt 0.12.0, and android-plugin from the tip of the repo, this happens:

Following the instructions in the Getting Started guide, the resulting project compiles, installs, but fails to start with the error:

08-12 11:30:03.129: E/AndroidRuntime(30468): java.lang.NoClassDefFoundError: org.abstractbinary.combien.R$layout

Adding the following to fullAndroidSettings in `Build.scala' seems to fix the problem:

 ++ Seq (
  compileOrder := CompileOrder.JavaThenScala
)

I haven't been able to figure out what's going on or why that change fixes it.

scvalex commented 12 years ago

I think I've gotten to the bottom of this.

During build, there were a bunch of warnings like the following:

trouble processing:
bad class file magic (cafebabe) or version (0033.0000)
...while parsing org/abstractbinary/combien/R$layout.class
...while processing org/abstractbinary/combien/R$layout.class

Turns out it's the DEX compiler, dx, complaining that it can't understand Java 7 bytecode. The fix is to tell javac to output Java 6 bytecode:

javacOptions ++= Seq("-source", "1.6", "-target", "1.6"),

I think the problems now are:

  1. why was the above error treated like a warning,
  2. why did setting compileOrder seem to fix the issue.
pligor commented 12 years ago

Hello scvalex! Many thanks for sharing. I get the exactly same problem bad class file magic (cafebabe) or version (0033.0000)

I think your solution is close to the solutions of this stackoverflow: http://stackoverflow.com/questions/7866723/dx-bad-class-file-magic-cafebabe-or-version-0033-0000-with-adk14

but I still haven't been able to make it work!

Where do you exactly copy paste this line? javacOptions ++= Seq("-source", "1.6", "-target", "1.6") I tried inside the project/plugins.sbt or inside Build.scala but I didn't notice any difference...

You also mention: why did setting compileOrder seem to fix the issue but how do you use it exactly?

Thank you!

scvalex commented 12 years ago

Here's the Build.scala I'm using:

https://github.com/scvalex/combien/blob/master/project/Build.scala

I don't know why changing compileOrder seemed to fix the problem (it didn't, really).

pligor commented 12 years ago

Hey thanks for the response! Your case of Build.scala really fixed my problem with the warnings but now I get a different warning: warning: [options] bootstrap class path not set in conjunction with -source 1.6

I'll keep on trying with your code in mind to see if I can make it work. Till now I only get the same thing. As soon as the Main Activity tries to start it crashes!

Anyway I am trying to create a How-To For Dummies on how to setup android + scala + intellij on ubuntu as for others to avoid spending (at least) two days hacking around with no luck as me! I have uploaded this wiki on multiupload in case you could find some time to help! Probably all the steps I have followed in this wiki are familiar to you. It's at the end that I am stuck... So here is the link: http://www.multiupload.nl/DCDG7IFD5J

scvalex commented 12 years ago

warning: [options] bootstrap class path not set in conjunction with -source 1.6

I get that too, but it hasn't caused a problem yet.

As soon as the Main Activity tries to start it crashes!

My suggestion would be to check ddms for the exact error, but whatever it is, it's not the issue reported here anymore.