让Android在Scala中发挥出色

时间:2018-06-18 10:01:47

标签: android scala akka proguard

我的Android项目中使用的其中一个库包含Akka及其相应的Scala依赖项。每当我运行该项目时,我都会收到以下错误消息:

Exception in thread "main" java.lang.IllegalArgumentException: Unexpected private interface method checkCreatorClosingOver.akka/actor/AbstractProps : (Ljava/lang/Class;)V
    at com.google.common.base.Preconditions.checkArgument(Preconditions.java:399)
    at com.google.devtools.build.android.desugar.InterfaceDesugaring.visitMethod(InterfaceDesugaring.java:206)
    at org.objectweb.asm.ClassVisitor.visitMethod(ClassVisitor.java:327)
    at com.google.devtools.build.android.desugar.LambdaDesugaring.visitMethod(LambdaDesugaring.java:193)
    at org.objectweb.asm.ClassReader.readMethod(ClassReader.java:1020)
    at org.objectweb.asm.ClassReader.accept(ClassReader.java:698)
    at org.objectweb.asm.ClassReader.accept(ClassReader.java:500)
    at com.google.devtools.build.android.desugar.Desugar.desugarClassesInInput(Desugar.java:477)
    at com.google.devtools.build.android.desugar.Desugar.desugarOneInput(Desugar.java:361)
    at com.google.devtools.build.android.desugar.Desugar.desugar(Desugar.java:314)
    at com.google.devtools.build.android.desugar.Desugar.main(Desugar.java:711)

Exception in thread "main" java.lang.IllegalArgumentException: Unexpected private interface method grow.scala/util/parsing/combinator/PackratParsers : (Lscala/util/parsing/combinator/Parsers$Parser;Lscala/util/parsing/combinator/PackratParsers$PackratReader;Lscala/util/parsing/combinator/PackratParsers$Head;)Lscala/util/parsing/combinator/Parsers$ParseResult;
    at com.google.common.base.Preconditions.checkArgument(Preconditions.java:399)
    at com.google.devtools.build.android.desugar.InterfaceDesugaring.visitMethod(InterfaceDesugaring.java:206)
    at org.objectweb.asm.ClassVisitor.visitMethod(ClassVisitor.java:327)
    at com.google.devtools.build.android.desugar.LambdaDesugaring.visitMethod(LambdaDesugaring.java:193)
    at org.objectweb.asm.ClassReader.readMethod(ClassReader.java:1020)
    at org.objectweb.asm.ClassReader.accept(ClassReader.java:698)
    at org.objectweb.asm.ClassReader.accept(ClassReader.java:500)
    at com.google.devtools.build.android.desugar.Desugar.desugarClassesInInput(Desugar.java:477)
    at com.google.devtools.build.android.desugar.Desugar.desugarOneInput(Desugar.java:361)
    at com.google.devtools.build.android.desugar.Desugar.desugar(Desugar.java:314)
    at com.google.devtools.build.android.desugar.Desugar.main(Desugar.java:711)

Exception in thread "main" java.lang.IllegalStateException: Expected a load for Lscala/Function1; to set up parameter 0 for scala/ScalaReflectionException$$Lambda$0 but got -1
    at com.google.common.base.Preconditions.checkState(Preconditions.java:756)
    at com.google.devtools.build.android.desugar.LambdaDesugaring$InvokedynamicRewriter.attemptAllocationBeforeArgumentLoads(LambdaDesugaring.java:543)
    at com.google.devtools.build.android.desugar.LambdaDesugaring$InvokedynamicRewriter.visitInvokeDynamicInsn(LambdaDesugaring.java:427)
    at org.objectweb.asm.ClassReader.readCode(ClassReader.java:1623)
    at org.objectweb.asm.ClassReader.readMethod(ClassReader.java:1126)
    at org.objectweb.asm.ClassReader.accept(ClassReader.java:698)
    at org.objectweb.asm.ClassReader.accept(ClassReader.java:500)
    at com.google.devtools.build.android.desugar.Desugar.desugarClassesInInput(Desugar.java:477)
    at com.google.devtools.build.android.desugar.Desugar.desugarOneInput(Desugar.java:361)
    at com.google.devtools.build.android.desugar.Desugar.desugar(Desugar.java:314)
    at com.google.devtools.build.android.desugar.Desugar.main(Desugar.java:711)

Exception in thread "main" java.lang.IllegalArgumentException: Unexpected private interface method rec$1.play/core/formatters/Multipart$Formatter : (ILjava/lang/String;)Lplay/core/formatters/Multipart$Formatter;
    at com.google.common.base.Preconditions.checkArgument(Preconditions.java:399)
    at com.google.devtools.build.android.desugar.InterfaceDesugaring.visitMethod(InterfaceDesugaring.java:206)
    at org.objectweb.asm.ClassReader.readMethod(ClassReader.java:1020)
    at org.objectweb.asm.ClassReader.accept(ClassReader.java:698)
    at org.objectweb.asm.ClassReader.accept(ClassReader.java:500)
    at com.google.devtools.build.android.desugar.Desugar.desugarClassesInInput(Desugar.java:477)
    at com.google.devtools.build.android.desugar.Desugar.desugarOneInput(Desugar.java:361)
    at com.google.devtools.build.android.desugar.Desugar.desugar(Desugar.java:314)
    at com.google.devtools.build.android.desugar.Desugar.main(Desugar.java:711)

在我的proguard文件中,我添加了以下规则以尝试缓解此问题:

## akka START
-keep class com.typesafe.**
-keep class akka.**
-keep class scala.collection.immutable.StringLike {
    *;
}
-keepclasseswithmembers class * {
    public <init>(java.lang.String, akka.actor.ActorSystem$Settings, akka.event.EventStream, akka.actor.Scheduler, akka.actor.DynamicAccess);
}
-keepclasseswithmembers class * {
    public <init>(akka.actor.ExtendedActorSystem);
}
-keep class scala.collection.SeqLike {
    public protected *;
}


  -keep class akka.actor.LightArrayRevolverScheduler { *; }
  -keep class akka.actor.LocalActorRefProvider { *; }
  -keep class akka.actor.CreatorFunctionConsumer { *; }
  -keep class akka.actor.TypedCreatorFunctionConsumer { *; }
  -keep class akka.dispatch.BoundedDequeBasedMessageQueueSemantics { *; }
  -keep class akka.dispatch.UnboundedMessageQueueSemantics { *; }
  -keep class akka.dispatch.UnboundedDequeBasedMessageQueueSemantics { *; }
  -keep class akka.dispatch.DequeBasedMessageQueueSemantics { *; }
  -keep class akka.actor.LocalActorRefProvider$Guardian { *; }
  -keep class akka.actor.LocalActorRefProvider$SystemGuardian { *; }
  -keep class akka.dispatch.UnboundedMailbox { *; }
  -keep class akka.actor.DefaultSupervisorStrategy { *; }
  -keep class akka.event.Logging$LogExt { *; }

## akka END

我仍然无法让项目编译并成功运行。我能做些什么才能让它发挥作用?

1 个答案:

答案 0 :(得分:0)

最新版本的Akka(和Scala)需要Java 8,据我所知,它无法在仅支持Java 7或6的android上运行。