cordova:transformClassesWithDexForReleaseDex:将字节码转换为dex时出错

时间:2018-11-06 16:24:47

标签: cordova android-gradle

过去几天,我一直在与这个问题作斗争,并尝试了一些建议的修复程序。其中之一(使用杰克)有效,但

  1. 将构建所需的时间和内存加倍
  2. 杰克已弃用

我还尝试更新CordovaLib / build.gradle中指定的Java版本,但这似乎也不能解决问题。

我正在运行cordova 7.1.0,升级可能不是一个简单的选择。 和Java 1.8.0

观察

以下命令无法生成:

cordova --release build android --device

使用

:transformClassesWithDexForReleaseDex: Error converting bytecode to dex:
Cause: Dex cannot parse version 52 byte code.
This is caused by library dependencies that have been compiled using 
Java 8 or above.
If you are using the 'java' gradle plugin in a library submodule add 
targetCompatibility = '1.7'
sourceCompatibility = '1.7'
to that submodule's build.gradle file.
    UNEXPECTED TOP-LEVEL EXCEPTION:
java.lang.RuntimeException: Exception parsing classes
    at com.android.dx.command.dexer.Main.processClass(Main.java:775)
    at com.android.dx.command.dexer.Main.processFileBytes(Main.java:741)
    at com.android.dx.command.dexer.Main.access$1200(Main.java:88)
    at com.android.dx.command.dexer.Main$FileBytesConsumer.processFileBytes(Main.java:1683)
    at com.android.dx.cf.direct.ClassPathOpener.processArchive(ClassPathOpener.java:284)
    at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:166)
    at com.android.dx.cf.direct.ClassPathOpener.process(ClassPathOpener.java:144)
    at com.android.dx.command.dexer.Main.processOne(Main.java:695)
    at com.android.dx.command.dexer.Main.processAllFiles(Main.java:592)
    at com.android.dx.command.dexer.Main.runMonoDex(Main.java:321)
    at com.android.dx.command.dexer.Main.run(Main.java:292)
    at com.android.builder.internal.compiler.DexWrapper.run(DexWrapper.java:54)
    at com.android.builder.core.DexByteCodeConverter.lambda$dexInProcess$0(DexByteCodeConverter.java:173)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:748)
Caused by: com.android.dx.cf.iface.ParseException: bad class file magic (cafebabe) or version (0034.0000)
    at com.android.dx.cf.direct.DirectClassFile.parse0(DirectClassFile.java:476)
    at com.android.dx.cf.direct.DirectClassFile.parse(DirectClassFile.java:406)
    at com.android.dx.cf.direct.DirectClassFile.parseToInterfacesIfNecessary(DirectClassFile.java:388)
    at com.android.dx.cf.direct.DirectClassFile.getMagic(DirectClassFile.java:251)
    at com.android.dx.command.dexer.Main.parseClass(Main.java:787)
    at com.android.dx.command.dexer.Main.access$1600(Main.java:88)
    at com.android.dx.command.dexer.Main$ClassParserTask.call(Main.java:1722)
    at com.android.dx.command.dexer.Main.processClass(Main.java:773)
    ... 16 more

但是,确实会建立以下内容:

( cd platforms/android ; ./gradlew cdvBuildRelease -b build.gradle )

在那之后,以下内容也会建立(即使以前没有)

cordova --release build android --device

最后,如果我清理了构建,我会回到不构建的状态。

( cd platforms/android ; ./gradlew clean )
cordova --release build android --device

不确定下一步该怎么做。

1 个答案:

答案 0 :(得分:0)

您是否尝试过像这样在Gradle版本中更改此设置? targetCompatibility ='1.7' sourceCompatibility ='1.8'

如果执行CLEAN清除所有的.class文件,然后将它们重新编译为1.7格式,则应该很好。

只需确保在更改Gradle构建中的值(如上所示)后进行一次干净的操作即可。