Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remote akka actors on android?

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)
like image 247
Ray Goodwin Avatar asked Apr 28 '12 14:04

Ray Goodwin


2 Answers

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)

like image 145
Björn Harrtell Avatar answered Oct 22 '22 17:10

Björn Harrtell


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.

like image 39
Ant Kutschera Avatar answered Oct 22 '22 17:10

Ant Kutschera