ProGuard使用sbt-proguard说不支持的类版本号[52.0](最大51.0,Java 1.7)

时间:2014-04-19 13:14:25

标签: sbt proguard java-8

我在 Mac OS X 10.9.2 sbt 0.13.3-SNAPSHOT (从源代码构建), Java 8 sbt-proguard 0.2.2 插件。

sbt 0.13.3-SNAPSHOT

[jacek]> sbtVersion
[info] 0.13.3-SNAPSHOT

Java 8

$ /Library/Java/JavaVirtualMachines/jdk1.8.0.jdk/Contents/Home/bin/java -version
java version "1.8.0"
Java(TM) SE Runtime Environment (build 1.8.0-b132)
Java HotSpot(TM) 64-Bit Server VM (build 25.0-b70, mixed mode)

项目/ plugins.sbt

addSbtPlugin("com.typesafe.sbt" % "sbt-proguard" % "0.2.2")

当我在sbt shell中运行proguard:proguard时,会出现以下异常:

[sbt-updates]> show proguard:proguard
[info] ProGuard, version 4.9
[info] Reading program directory [/Users/jacek/oss/sbt-updates/target/scala-2.10/sbt-0.13/classes] (filtered)
[info] Reading program jar [/Users/jacek/.ivy2/cache/org.scalaz/scalaz-concurrent_2.10/bundles/scalaz-concurrent_2.10-7.1.0-M6.jar] (filtered)
[info] Reading program jar [/Users/jacek/.sbt/boot/scala-2.10.3/lib/scala-library.jar] (filtered)
[info] Reading program jar [/Users/jacek/.ivy2/cache/org.scalaz/scalaz-core_2.10/bundles/scalaz-core_2.10-7.1.0-M6.jar] (filtered)
[info] Reading program jar [/Users/jacek/.ivy2/cache/org.scalaz/scalaz-effect_2.10/bundles/scalaz-effect_2.10-7.1.0-M6.jar] (filtered)
[info] Reading library jar [/Library/Java/JavaVirtualMachines/jdk1.8.0.jdk/Contents/Home/jre/lib/rt.jar]
[error] Error: Can't read [/Library/Java/JavaVirtualMachines/jdk1.8.0.jdk/Contents/Home/jre/lib/rt.jar] (Can't process class [apple/applescript/AppleScriptEngine.class] (Unsupported class version number [52.0] (maximum 51.0, Java 1.7)))
[trace] Stack trace suppressed: run last proguard:proguard for the full output.
[error] (proguard:proguard) Proguard failed with exit code [1]
[error] Total time: 16 s, completed Apr 19, 2014 2:27:56 PM

为什么可能是错误的原因?

4 个答案:

答案 0 :(得分:8)

ProGuard和sbt-proguard似乎还不支持Java 8,并且更改了脚本中用于启动sbt帮助的Java版本。

[sbt-updates]> show proguard:proguard
[info] Compiling 8 Scala sources to /Users/jacek/oss/sbt-updates/target/scala-2.10/sbt-0.13/classes...
[warn] there were 6 feature warning(s); re-run with -feature for details
[warn] one warning found
[info] ProGuard, version 4.9
[info] Reading program directory [/Users/jacek/oss/sbt-updates/target/scala-2.10/sbt-0.13/classes] (filtered)
[info] Reading program jar [/Users/jacek/.ivy2/cache/org.scalaz/scalaz-concurrent_2.10/bundles/scalaz-concurrent_2.10-7.1.0-M6.jar] (filtered)
...

使用以下版本的 Java 7

$ /Library/Java/JavaVirtualMachines/jdk1.7.0_51.jdk/Contents/Home/bin/java -version
java version "1.7.0_51"
Java(TM) SE Runtime Environment (build 1.7.0_51-b13)
Java HotSpot(TM) 64-Bit Server VM (build 24.51-b03, mixed mode)

答案 1 :(得分:3)

通过将proguardVersion中的密钥build.sbt更改为5.0以上的设置,可以更新sbt-proguard使用的Proguard版本,例如:

ProguardKeys.proguardVersion in Proguard := "5.2.1"

请参阅:https://github.com/sbt/sbt-proguard/issues/5

答案 2 :(得分:3)

这个问题真的很有趣,我面临的是同一个问题,唯一的区别是我使用maven以编程方式添加了Proguard。因此,我认为发布我的解决方案会有所帮助,尽管它与主要问题有所不同。对于所有使用maven并遇到相同问题的用户,我的解决方法是通过在插件内部将其用作运行时来更新Proguard的版本,因此工作pom.xml看起来像这样

  <plugin>
                    <groupId>com.github.wvengen</groupId>
                    <artifactId>proguard-maven-plugin</artifactId>
                    <version>2.0.14</version>
                    <executions>
                        <execution>
                            <phase>package</phase>
                            <goals>
                                <goal>proguard</goal>
                            </goals>
                        </execution>
                    </executions>
                    <configuration>
                        <obfuscate>true</obfuscate>
                        <attach>true</attach>
                        <appendClassifier>false</appendClassifier>
                        <addMavenDescriptor>true</addMavenDescriptor>
                        <injar>${project.build.finalName}-jar-with-dependencies.jar</injar>
                        <injarNotExistsSkip>true</injarNotExistsSkip>
                        <libs>
                            <lib>${java.home}/lib/rt.jar</lib>
                            <lib>${java.home}/lib/jce.jar</lib>
                            <lib>${java.home}/lib/ext/sunjce_provider.jar</lib>
                        </libs>
                        <options>
                        <option>-allowaccessmodification</option>
                        <option>-optimizationpasses 3</option>
                        <option>-overloadaggressively</option>
                        <option>-repackageclasses ''</option>
                        <option>-dontusemixedcaseclassnames</option>
                        <option>-dontskipnonpubliclibraryclasses</option>
                        <option>-flattenpackagehierarch</option>
                        <option>-dontwarn</option> <!-- added option to ignore com.sun missing classes -->
                            <option>-keep public class com.StocksNews.App {
                                public static void main(java.lang.String[]);
                                }
                            </option>
                        </options>
                    </configuration>
                    <dependencies>
                        <dependency>
                            <groupId>net.sf.proguard</groupId>
                            <artifactId>proguard-base</artifactId>
                            <version>6.1.1</version>
                            <scope>runtime</scope>
                        </dependency>
                    </dependencies>
                </plugin>

答案 3 :(得分:0)

我通过以下链接更新了ProGuad的最新版本,从而解决了该问题

Sourceforge ProGuard page