How to use Akka project under Android

2019-07-10 16:30发布

问题:

I'm a little bit desperate at the moment. I'm trying to use an Akka project (written in scala) under Android (in Eclipse), but whatever I try, I can't make it work.
For simplicity I created two projects: One Akka project, created using sbt eclipse and then imported to eclipse, and one standard android project using the project creation wizard. I can reference the Akka-code from the android code, but at Runtime I always get a NoClassDefFoundError.
I would really appreciate if someone could point out what I'm doing wrong or what I could in general do to use my Akka project in my Android app.

回答1:

I feel your pain. I spent hours trying to get sbt, proguard, scala, akka to work, and recommend you take a look at the project/Build.scala from here:

https://github.com/fehguy/swagger-for-the-home/tree/master/android

Specifically the proguard options:

proguardOption in Android :=
  """
    |-dontwarn scala.**
    |-keepclassmembers class * {
    |    ** MODULE$;
    |}
    |-keep class scala.collection.SeqLike {
    |    public protected *;
    |}
    |-keep public class * extends android.app.Activity
    |-keep public class * extends android.app.Application
    |-keep public class * extends android.app.Service
    |-keep public class * extends android.content.BroadcastReceiver
    |-keep public class * extends android.content.ContentProvider
    |-keep public class * extends android.app.backup.BackupAgentHelper
    |-keep public class * extends android.preference.Preference
    |-keep public class com.android.vending.licensing.ILicensingService
    |-keep public class org.eatbacon.sfth.AnalogUpdateActivity
    |-keep public class org.eatbacon.sfth.UpdateDataTask
    |-keep public class org.eatbacon.sfth.ShowChartActivity
    |
    |-keepclasseswithmembernames class * {
    |    native <methods>;
    |}
    |
    |-keepclasseswithmembernames class * {
    |    public <init>(android.content.Context, android.util.AttributeSet);
    |}
    |
    |-keepclasseswithmembernames class * {
    |    public <init>(android.content.Context, android.util.AttributeSet, int);
    |}
    |
    |-keepclassmembers enum * {
    |    public static **[] values();
    |    public static ** valueOf(java.lang.String);
    |}
    |
    |-keep class * implements android.os.Parcelable {
    |  public static final android.os.Parcelable$Creator *;
    |}
  """.stripMargin

)



回答2:

I'm firing blind without seeing a stack trace, but it sounds like you didn't export the Akka project from the Android project.

  1. Open your Android project in Eclipse.
  2. Right click on your Android project in Project Explorer.
  3. Select Build Path --> Configure Build Path from the menu.
  4. When the dialog appears, go to the Order and Export tab, then make sure your Akka project is checked.