Proguard-java.lang.IllegalArgumentException:找不到常见的父类

发布时间:2020-07-07 15:32

我刚刚将项目中的Java版本从8切换到了11,现在我在使用以下选项的Proguard 6.2.2和sbt-proguard 0.3.0时遇到了问题:

-dontnote,
-dontwarn,
-dontoptimize,
-dontusemixedcaseclassnames,
-keep public class org.slf4j.** { *; },
-keep public class ch.** { *; },
-keep class org.bouncycastle.** { *; },
-keepnames public class * {
  public static ** classTag();
  },
-keepclasseswithmembers public class * {
   public static void main(java.lang.String[]);
  },
-keepclassmembers class * {
  ** MODULE$;
  },
-keepclasseswithmembernames,includedescriptorclasses class * {
  native <methods>;
  },
-keepclassmembers,allowoptimization enum * {
  public static **[] values();
  public static ** valueOf(java.lang.String);
  },
-keepattributes SourceFile,LineNumberTable

这是堆栈跟踪:

Unexpected error while performing partial evaluation:
   Class       = [akka/actor/ActorSelection$$anonfun$1]
   Method      = [applyOrElse(Ljava/lang/String;Lscala/Function1;)Ljava/lang/Object;]
   Exception   = [java.lang.IllegalArgumentException] (Can't find common super class of [akka/actor/SelectChildPattern] (with 1 known super classes) and [akka/actor/SelectChildName] (with 1 known super classes))
 Unexpected error while preverifying:
   Class       = [akka/actor/ActorSelection$$anonfun$1]
   Method      = [applyOrElse(Ljava/lang/String;Lscala/Function1;)Ljava/lang/Object;]
   Exception   = [java.lang.IllegalArgumentException] (Can't find common super class of [akka/actor/SelectChildPattern] (with 1 known super classes) and [akka/actor/SelectChildName] (with 1 known super classes))
 Error: Can't find common super class of [akka/actor/SelectChildPattern] (with 1 known super classes) and [akka/actor/SelectChildName] (with 1 known super classes)
 java.lang.RuntimeException: Proguard failed with exit code [1]
   at scala.sys.package$.error(package.scala:30)
   at com.lightbend.sbt.SbtProguard$.runProguard(SbtProguard.scala:114)
   at com.lightbend.sbt.SbtProguard$.$anonfun$proguardTask$2(SbtProguard.scala:94)
   at sbt.util.FileFunction$.$anonfun$cached$1(FileFunction.scala:73)
   at sbt.util.FileFunction$.$anonfun$cached$4(FileFunction.scala:146)
   at sbt.util.Difference.apply(Tracked.scala:323)
   at sbt.util.Difference.apply(Tracked.scala:303)
   at sbt.util.FileFunction$.$anonfun$cached$3(FileFunction.scala:142)
   at sbt.util.Difference.apply(Tracked.scala:323)
   at sbt.util.Difference.apply(Tracked.scala:298)
   at sbt.util.FileFunction$.$anonfun$cached$2(FileFunction.scala:141)
   at com.lightbend.sbt.SbtProguard$.$anonfun$proguardTask$1(SbtProguard.scala:98)
   at scala.Function1.$anonfun$compose$1(Function1.scala:49)
   at sbt.internal.util.$tilde$greater.$anonfun$$u2219$1(TypeFunctions.scala:62)
   at sbt.std.Transform$$anon$4.work(Transform.scala:67)
   at sbt.Execute.$anonfun$submit$2(Execute.scala:281)
   at sbt.internal.util.ErrorHandling$.wideConvert(ErrorHandling.scala:19)
   at sbt.Execute.work(Execute.scala:290)
   at sbt.Execute.$anonfun$submit$1(Execute.scala:281)
   at sbt.ConcurrentRestrictions$$anon$4.$anonfun$submitValid$1(ConcurrentRestrictions.scala:178)
   at sbt.CompletionService$$anon$2.call(CompletionService.scala:37)
   at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
   at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
   at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
   at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
   at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
   at java.base/java.lang.Thread.run(Thread.java:834)

我尝试添加这些选项时没有运气:

-keep class akka.actor.** { *; },
-keep interface akka.actor.** { *; },
-keep enum akka.actor.** { *; },
-keep class akka.actor.SelectChildPattern { *; },
-keep class akka.actor.ActorSelection { *; },
-keep class akka.actor.SelectChildName { *; }

我可以看到Akka在图书馆的罐子里:

[debug] -libraryjars "/Users/izhavoronkov/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/com/typesafe/akka/akka-actor_2.12/2.5.26/akka-actor_2.12-2.5.26.jar"

此外,如果我设置了-dontpreverify,我可以在jar中找到丢失的Akka类,并且它们不会像预期的那样被混淆。不知道proguard或config有什么问题。

我在Java 8中没有这些问题。

回答1

通过添加-libraryjars $java_home_11/jmods/java.base.jmod参数来解决该问题