记录一个Java 编译版本引发的报错,项目中使用的 jdk 8 编译,而依赖的 jar 包默认使用 java9 编译。
报错日志:
Caused by: com.android.builder.dexing.DexArchiveBuilderException: Failed to process /Users/jacinth/.gradle/caches/modules-2/files-2.1/org.bouncycastle/bcprov-jdk15on/1.62/633b6739ef8f07f2e71f8eebd1c6f25b17a4ec7d/bcprov-jdk15on-1.62.jar
at com.android.build.gradle.internal.transforms.DexArchiveBuilderTransform.launchProcessing(DexArchiveBuilderTransform.java:550)
at com.android.build.gradle.internal.transforms.DexArchiveBuilderTransform.lambda$convertToDexArchive$1(DexArchiveBuilderTransform.java:488)
at java.util.concurrent.ForkJoinTask$AdaptedCallable.exec(ForkJoinTask.java:1424)
at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:289)
at java.util.concurrent.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1056)
at java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1692)
at java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:157)
Caused by: com.android.builder.dexing.DexArchiveBuilderException: Error while dexing META-INF/versions/9/module-info.class
at com.android.builder.dexing.DxDexArchiveBuilder.getExceptionToRethrow(DxDexArchiveBuilder.java:143)
at com.android.builder.dexing.DxDexArchiveBuilder.convert(DxDexArchiveBuilder.java:89)
at com.android.build.gradle.internal.transforms.DexArchiveBuilderTransform.launchProcessing(DexArchiveBuilderTransform.java:545)
... 6 more
Caused by: com.android.dx.cf.iface.ParseException: unsupported class file version 53.0
at com.android.dx.cf.direct.DirectClassFile.parse0(DirectClassFile.java:499)
at com.android.dx.cf.direct.DirectClassFile.parse(DirectClassFile.java:420)
at com.android.dx.cf.direct.DirectClassFile.parseToInterfacesIfNecessary(DirectClassFile.java:402)
at com.android.dx.cf.direct.DirectClassFile.getMagic(DirectClassFile.java:253)
at com.android.builder.dexing.DxDexArchiveBuilder.dex(DxDexArchiveBuilder.java:99)
at com.android.builder.dexing.DxDexArchiveBuilder.convert(DxDexArchiveBuilder.java:86)
... 7 more
原因:
引入的 jar 包的编译版本比 android studio 使用的 jdk 版本要高,导致 jar 包编译报错。
解决:
(1)使用更高版本的 jdk(推荐)
(2)删除?module-info.class 文件。(这个方法应该不是对每个人都有效,报错日志里明确指出了该文件报错,可以使用 WinRAR 打开 jar 包,进入对应的目录删除报错的文件,再重新在项目中依赖,如果编译不报错就可行)
附一份 java 版本号对应表
Java SE 9 = 53,
Java SE 8 = 52,
Java SE 7 = 51,
Java SE 6.0 = 50,
Java SE 5.0 = 49,
JDK 1.4 = 48,
JDK 1.3 = 47,
JDK 1.2 = 46,
JDK 1.1 = 45
|