5

Im trying to make a simple remote connection to a actor using akka as I normally do but Im sure there something else I need to do when using akka from android can anyone help?

import akka.actor.Actor.remote

// Establish Connection to Remote Actor                
val server = remote.actorFor(remoteActorID, rIP, rPort)

I get te following stack trace:

04-28 09:57:13.114: ERROR/AndroidRuntime(18536): FATAL EXCEPTION: Thread-741
        java.lang.ExceptionInInitializerError
        at akka.actor.Actor$.remote(Actor.scala:115)
        at edu.spsu.rgoodwin.networking.api.RemoteConnection.<init>(RemoteConnection.scala:18)
        at edu.spsu.rgoodwin.csrAndroidApp.ClientConfigActivity.routerRegistration(ClientConfigActivity.scala:234)
        at edu.spsu.rgoodwin.csrAndroidApp.ClientConfigActivity$$anon$1.run(ClientConfigActivity.scala:71)
        at java.lang.Thread.run(Thread.java:856)
        Caused by: java.lang.ExceptionInInitializerError
        at akka.util.ReflectiveAccess$Remote$.<init>(ReflectiveAccess.scala:52)
        at akka.util.ReflectiveAccess$Remote$.<clinit>(ReflectiveAccess.scala)
        ... 5 more
        Caused by: akka.config.ConfigurationException: Event Handler specified in config can't be loaded [akka.event.EventHandler$DefaultListener] due to [java.lang.ClassNotFoundException: akka.event.EventHandler$DefaultListener]
        [localhost_0e3e4c40-913a-11e1-b984-660379e93466]
        at akka.event.EventHandler$$anonfun$1.apply(EventHandler.scala:231)
        at akka.event.EventHandler$$anonfun$1.apply(EventHandler.scala:223)
        at scala.collection.LinearSeqOptimized$class.foreach(LinearSeqOptimized.scala:59)
        at scala.collection.immutable.List.foreach(List.scala:45)
        at akka.event.EventHandler$.<init>(EventHandler.scala:223)
        at akka.event.EventHandler$.<clinit>(EventHandler.scala)
        ... 7 more
        Caused by: java.lang.ClassNotFoundException: akka.event.EventHandler$DefaultListener
        at java.lang.Class.classForName(Native Method)
        at java.lang.Class.forName(Class.java:217)
        at java.lang.Class.forName(Class.java:172)
        at akka.util.ReflectiveAccess$.getClassFor(ReflectiveAccess.scala:222)
        at akka.event.EventHandler$$anonfun$1.apply(EventHandler.scala:225)
        ... 12 more
        Caused by: java.lang.NoClassDefFoundError: akka/event/EventHandler$DefaultListener
        ... 17 more
        Caused by: java.lang.ClassNotFoundException: akka.event.EventHandler$DefaultListener
        at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
Ray Goodwin
  • 183
  • 1
  • 3
  • 9
  • Is the akka jar deployed on the android client? The no class def exception seems to indicate its not. – Ant Kutschera Apr 28 '12 at 19:50
  • I used my build.sbt file to include akka and the app work fine until I request an connection to the remote actor. //Akka resolvers += "Typesafe Repository" at "http://repo.typesafe.com/typesafe/releases/" libraryDependencies += "se.scalablesolutions.akka" % "akka-actor" % "1.3" libraryDependencies += "se.scalablesolutions.akka" % "akka-actor" % "1.3" libraryDependencies += "se.scalablesolutions.akka" % "akka-remote" % "1.3" libraryDependencies += "se.scalablesolutions.akka" % "akka-stm" % "1.3" – Ray Goodwin Apr 28 '12 at 20:29

2 Answers2

7

I got it working with Akka 2.0.2 and Android 2.3.3. What you need to do is:

  1. Workaround that Akka jars include multiple reference.conf at the same path which proguard does not like. Do this by removing the reference.conf from the jars but instead including a custom reference.conf which includes config from both files in the jars.

  2. Configure Proguard to include classes from akka that are referenced by reflection and to ignore warnings about sun.misc.Unsafe. My config: https://gist.github.com/3307987

  3. Upgrade Netty to 3.3.1 (fixes problems with its usage of sun.misc.Unsafe)

Björn Harrtell
  • 211
  • 2
  • 1
3

Everything needs to be deployed In a single jar. See Is using Scala on Android worth it? Is there a lot of overhead? Problems? for more details of deploying Scala to android.

Community
  • 1
  • 1
Ant Kutschera
  • 6,257
  • 4
  • 29
  • 40