{"id":2305,"date":"2022-08-30T15:23:45","date_gmt":"2022-08-30T15:23:45","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/01\/05\/android-scala-intellij-sbt-returns-warning-and-app-crashes-on-emulator-bad-class-file-magic-cafebabe-or-version-0033-0000-collection-of-common-programming-errors\/"},"modified":"2022-08-30T15:23:45","modified_gmt":"2022-08-30T15:23:45","slug":"android-scala-intellij-sbt-returns-warning-and-app-crashes-on-emulator-bad-class-file-magic-cafebabe-or-version-0033-0000-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2022\/08\/30\/android-scala-intellij-sbt-returns-warning-and-app-crashes-on-emulator-bad-class-file-magic-cafebabe-or-version-0033-0000-collection-of-common-programming-errors\/","title":{"rendered":"android + scala + intellij sbt returns warning and app crashes on emulator: bad class file magic (cafebabe) or version (0033.0000)-Collection of common programming errors"},"content":{"rendered":"<p><strong>I am trying to get a hello world android app work with scala and intellij Whoever tried the same feat must be familiar with the following steps. The problem happens at the end when I am using the sbt<\/strong><\/p>\n<p>Please note the versions for each tool I use. For starters I am using the java version 1.7.0_07<\/p>\n<p>-Download and setup the android sdk. I have downloaded all versions from 1.5 (API 3) to 4.1 (API 16). I will not go into further details on this. There are many tutorials already.<\/p>\n<p>We are going to need the android home path in an enviroment variable. So let&#8217;s set a persistant enviroment variable for the current user<\/p>\n<pre><code>gedit ~\/.pam_environment\n<\/code><\/pre>\n<p>and now append this: ANDROID_HOME= e.g.<\/p>\n<pre><code>ANDROID_HOME=\/home\/pligor\/android-sdks\n<\/code><\/pre>\n<p>Now let&#8217;s grab the sbt tool. We would rather have a manual installation of sbt. Find the &#8220;Unix&#8221; section in the link: https:\/\/github.com\/harrah\/xsbt\/wiki\/Getting-Started-Setup and download sbt-launch.jar and place it in ~\/bin Currently this is version 0.12.0 Then create an sbt file:<\/p>\n<pre><code>gedit ~\/bin\/sbt\n<\/code><\/pre>\n<p>write this line inside:<\/p>\n<pre><code>java -Xms512M -Xmx1536M -Xss1M -XX:+CMSClassUnloadingEnabled -XX:MaxPermSize=384M -jar `dirname $0`\/sbt-launch.jar \"$@\"\n<\/code><\/pre>\n<p>and make script executable:<\/p>\n<pre><code>chmod u+x ~\/bin\/sbt\n<\/code><\/pre>\n<p>Now you need to install an sbt plugin for the intellij. The sbt-idea version 1.1.0:<\/p>\n<pre><code>gedit ~\/.sbt\/plugins\/build.sbt\n<\/code><\/pre>\n<p>add append inside the line (remember each .sbt files seperates each statement by an extra empty line):<\/p>\n<pre><code>addSbtPlugin(\"com.github.mpeltonen\" % \"sbt-idea\" % \"1.1.0\")\n<\/code><\/pre>\n<p>For github templates you need the giter8 tool. So execute:<\/p>\n<p>curl https:\/\/raw.github.com\/n8han\/conscript\/master\/setup.sh | sh<\/p>\n<p>and then execute:<\/p>\n<pre><code>cs n8han\/giter8\n<\/code><\/pre>\n<p>Now I use the g8 to get an android app template from jberkel:<\/p>\n<pre><code>g8 jberkel\/android-app\n<\/code><\/pre>\n<p>There are some questions for you to setup. Currently I leave everything to default. Which means I use scala version 2.9.1 and Android 2.3.3 (API 10) and scalatest_version of 1.8.RC1. I am not accustomed with proguard since I haven&#8217;t use it before so I set useProguard to false.<\/p>\n<p>Before you run sbt: The android-plugin is currently compatible with the 0.11.3 version of sbt we need to make an adjustment. So inside the folder of the new android application execute: gedit project\/build.properties and insert this line: sbt.version=0.11.3<\/p>\n<p>Inside the same folder execute: sbt &#8216;gen-idea no-classifiers&#8217; compile<\/p>\n<p>and then go to the sbt interactive mode console: sbt<\/p>\n<p>Inside the console execute: android:package-debug<\/p>\n<p><strong>And I believe these kind of warnings is where the problem starts:<\/strong> trouble processing: bad class file magic (cafebabe) or version (0033.0000) &#8230;while parsing my\/android\/project\/R$id.class<\/p>\n<p>Now you can try to start an android emulator: android:emulator-start # use to get a list of avds e.g. android:emulator-start android2_3_3<\/p>\n<p>after the emulator is fully started execute the android app like that: android:start-emulator<\/p>\n<p>AND AFTER ALL THIS THE APP WILL CRASH !!<\/p>\n<ol>\n<li>\n<p>The problem is with your Java version. Switch back to Java 6 or if you can&#8217;t, http:\/\/stackoverflow.com\/a\/7705091\/203487 might help.<\/p>\n<p>&#8220;bad class file magic (cafebabe) or version (0033.0000)&#8221; means the generated class files has a version of 51 which is Java 7, so it&#8217;s clear that neither the dexer nor ProGuard can work with these class files. Here I&#8217;m not talking about the latest ProGuard version but the one bundled with the Android SDK.<\/p>\n<\/li>\n<li>\n<p>I can only speak about my setup, which is kind of successful so far.<\/p>\n<ul>\n<li>You will need Proguard to create <code>apk<\/code>s of reasonable size.<\/li>\n<li>I use Scala <code>2.10-M6<\/code>, since <code>2.8<\/code> is old and has its quirks, especially with Android, and <code>2.9<\/code> is very slow to Proguard.<\/li>\n<li>The <code>keep class scala.collection.SeqLike { ...<\/code> is important otherwise the class is left out to the contrary it has a method references (I posted this workaround).<\/li>\n<li>The <code>Build.scala<\/code> uses many fun stuff like scalaz or libgdx, feel free to prune these. Many android stuff is hacked together from various g8 templates, thx for all the people sharing them.<\/li>\n<\/ul>\n<p>So here is a dump of my setup:<\/p>\n<p>project\/Build.scala project\/plugins.sbt<\/p>\n<p>I use <code>sbt 0.11.3<\/code> and <code>Idea 11.1<\/code>. I compile using the <code>sbt<\/code> console, mainly use the <code>android:start-device<\/code> command, and sometimes <code>android:emulator-start RomName<\/code> + <code>android:start-emulator<\/code>. Idea attaches nicely to the running Android process.<\/p>\n<p>I&#8217;m developing a small game with non-intensive graphics, and so far I used idiomatic Scala (and even Scalaz) without slowdowns. So no need to revert to arrays, vars and while loops just for the sake of Android \ud83d\ude42<\/p>\n<p>Good luck!<\/p>\n<\/li>\n<\/ol>\n<p id=\"rop\"><small>Originally posted 2014-01-05 10:08:04. <\/small><\/p>","protected":false},"excerpt":{"rendered":"<p>I am trying to get a hello world android app work with scala and intellij Whoever tried the same feat must be familiar with the following steps. The problem happens at the end when I am using the sbt Please note the versions for each tool I use. For starters I am using the java [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-2305","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/2305","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=2305"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/2305\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=2305"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=2305"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=2305"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}