{"id":2246,"date":"2012-01-31T00:12:27","date_gmt":"2012-01-30T23:12:27","guid":{"rendered":"http:\/\/www.gamlor.info\/wordpress\/?p=2246"},"modified":"2021-10-16T01:30:00","modified_gmt":"2021-10-16T00:30:00","slug":"running-akka-2-0-on-android-wip","status":"publish","type":"post","link":"https:\/\/www.gamlor.info\/wordpress\/2012\/01\/running-akka-2-0-on-android-wip\/","title":{"rendered":"Running Akka 2.0 On Android (WIP)"},"content":{"rendered":"<p><strong>This information here is allready quite outdated. With the current Akka 2.0 master snapshot some issues are gone, while new pitfalls introduced. I will update \/ create a new post when Akka 2.0 is close to the final release.<\/strong><\/p>\n<p>Akka 2.0 is available as a preview version. Here\u2019s a short guide how to get it to run on Android. This pretty much work in progress. Maybe someone else has even has a better strategy. Let me know if that\u2019s the case=). Also I didn\u2019t do much with Akka 2.0 on Android yet, so maybe there are major issues yet to discover =).<\/p>\n<div id=\"attachment_2249\" style=\"width: 310px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/www.gamlor.info\/wordpress\/wp-content\/uploads\/2012\/01\/akka20onDroid.png\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-2249\" class=\"size-medium wp-image-2249\" title=\"akka20onDroid\" src=\"https:\/\/www.gamlor.info\/wordpress\/wp-content\/uploads\/2012\/01\/akka20onDroid-300x226.png\" alt=\"Let's master this Akka beast, little Android =)\" width=\"300\" height=\"226\" srcset=\"https:\/\/www.gamlor.info\/wordpress\/wp-content\/uploads\/2012\/01\/akka20onDroid-300x226.png 300w, https:\/\/www.gamlor.info\/wordpress\/wp-content\/uploads\/2012\/01\/akka20onDroid.png 600w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><p id=\"caption-attachment-2249\" class=\"wp-caption-text\">Let's master this Akka-beast, little Android =)<\/p><\/div>\n<p>In general I just assume that you have a working Scala build and know how to include new Scala libraries. And I also assume that you are using Proguard to shrink the jar file. I use a build based on <a href=\"https:\/\/github.com\/pboos\/scala-on-android-example\">this<\/a>. In case you are having trouble, just ask for help =).<\/p>\n<p>First add the Akka 2.0 M3 jar-file to the project (The M2 bits won\u2019t work). Make sure that it is in your directories of libraries which are compacted by Proguard. Unfortunately you will get tons of warnings by Proguard about classes which couldn\u2019t be found, because they are not part of the Android platform. These are three categories of classes which are not available:<\/p>\n<ul>\n<li>\u2018 akka.util.JMX\u2019: There is no JMX on Android.<\/li>\n<li>\u2018sun.misc.Unsafe\u2019: Well at first sight Android doesn\u2019t have this implementation-detail class. Luckily it actually does have it (at least in newer versions), but it\u2019s only available at runtime. The jars which you compile against do not have this class.<\/li>\n<li>\u2018org.omg.CORBA\u2019-stuff. The Akka library has a UUID implementation which implements some interfaces from CORBA.<\/li>\n<\/ul>\n<p>So it is time for some Proguard trickery to get rid of warnings.<\/p>\n<h2>Bye Bye JMX<\/h2>\n<p>Well there is definitely no JMX on Android. So I just excluded the JMX stuff from Akka:<\/p>\n<script src=\"https:\/\/gist.github.com\/1706858.js?file=NoJMXForYou.cfg\"><\/script><noscript><pre><code class=\"language-ini ini\">## No JMX for Android\n-dontwarn akka.util.JMX*\n<\/code><\/pre><\/noscript>\n<h2>Ignoring \u2018sun.misc.Unsafe\u2019 Warnings<\/h2>\n<p>The next step is to configure Proguard to ignore the \u2018sun.misc.Unsafe\u2019 warnings. It is there on the device (If not, please tell me).<\/p>\n<script src=\"https:\/\/gist.github.com\/1706858.js?file=UnsafeIsThere.cfg\"><\/script><noscript><pre><code class=\"language-ini ini\">## Unsafe is there at runtime\n-dontwarn sun.misc.Unsafe\n-keep class sun.misc.Unsafe{\n    *;\n}<\/code><\/pre><\/noscript>\n<h2>Fixing the CORBA Stuff<\/h2>\n<div>\n<div>\n<div id=\"982189de-8479-41c6-9cec-ab6cfca78500\">\n<p>Well, just exclude the \u2018com.eaio.uuid\u2019 stuff and you should be fine. At least is looks like it when you are only using the basic functionality. (In Akka 1.2 the UUID class is central, in Akka 2.0 it has been replaced with the path system.):<\/p>\n<\/div>\n<\/div>\n<\/div>\n<script src=\"https:\/\/gist.github.com\/1706858.js?file=UUIDHelpersNotNeeded.cfg\"><\/script><noscript><pre><code class=\"language-ini ini\">## UUID helpers are not used\n-dontwarn com.eaio.uuid.**<\/code><\/pre><\/noscript>\n<h2>Remove the FSM Forward Reference<\/h2>\n<p>The core Akka library contains a forward reference to its finite state machine (FSM) implementation. In a usual class loader environment this doesn\u2019t matter, since classes are lazily loaded. However Proguard is going to bitch about it. So in case you are not using the FSM library remove that reference with Proguard:<\/p>\n<script src=\"https:\/\/gist.github.com\/1706858.js?file=FSM.cfg\"><\/script><noscript><pre><code class=\"language-ini ini\">## No Finate State Machines Support needed\n-dontwarn akka.actor.FSM<\/code><\/pre><\/noscript>\n<h2>Keep Important Classes<\/h2>\n<p>Also we need to keep some classes which are loaded at runtime. Maybe there are more required for some features, just watch for class loader errors. These are the ones you need for sure:<\/p>\n<script src=\"https:\/\/gist.github.com\/1706858.js?file=KeepStuff.cfg\"><\/script><noscript><pre><code class=\"language-ini ini\">## Stuff referenced at runtime\n-keep public class akka.actor.LocalActorRefProvider {\n   public &lt;init&gt;(...);\n}\n-keep class akka.event.Logging*\n-keep class akka.event.Logging$LogExt{\n    *;\n}<\/code><\/pre><\/noscript>\n<h2>Work Around the Reference Configuration Issue?<\/h2>\n<p>I\u2019m not sure what exactly the issue is here and probably I\u2019m doing something wrong. At least with my setup Akka cannot find its internal reference.conf resource file. Looks like resources are only loaded from the *.apk file? Anyway, for now I just copied the reference.conf file from the Akka source code to my project (Or do it with a build task). Then everything runs.<\/p>\n<h2>Conclusion<\/h2>\n<p>Yes, it is a little hairy to get Akka 2.0 to run on Android. I certainly will work a little more on it. And in case it gets too bad I\u2019ll do a shallow fork of Akka ;).<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This information here is allready quite outdated. With the current Akka 2.0 master snapshot some issues are gone, while new pitfalls introduced. I will update \/ create a new post&hellip; <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":"","_links_to":"","_links_to_target":""},"categories":[243,17],"tags":[245,297,244,226],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.gamlor.info\/wordpress\/wp-json\/wp\/v2\/posts\/2246"}],"collection":[{"href":"https:\/\/www.gamlor.info\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.gamlor.info\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.gamlor.info\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.gamlor.info\/wordpress\/wp-json\/wp\/v2\/comments?post=2246"}],"version-history":[{"count":8,"href":"https:\/\/www.gamlor.info\/wordpress\/wp-json\/wp\/v2\/posts\/2246\/revisions"}],"predecessor-version":[{"id":3911,"href":"https:\/\/www.gamlor.info\/wordpress\/wp-json\/wp\/v2\/posts\/2246\/revisions\/3911"}],"wp:attachment":[{"href":"https:\/\/www.gamlor.info\/wordpress\/wp-json\/wp\/v2\/media?parent=2246"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.gamlor.info\/wordpress\/wp-json\/wp\/v2\/categories?post=2246"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.gamlor.info\/wordpress\/wp-json\/wp\/v2\/tags?post=2246"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}