META-INF/versions/9/module-info.class:损坏的类文件?(此功能需要ASM6) [英] META-INF/versions/9/module-info.class: broken class file? (This feature requires ASM6)
问题描述
我遇到了Bouncycastle的问题,仅在运行:lint
任务时才会出现.
I'm having issues with Bouncycastle, which only arise when running the :lint
task.
通常它似乎是Java 9字节码版本53.0/ ASM 版本冲突.
Generally it seems to be a Java 9 byte-code version 53.0 / ASM version conflict.
这些是依赖项:
// https://mvnrepository.com/artifact/org.bouncycastle
implementation "org.bouncycastle:bcprov-jdk15on:1.64"
implementation "org.bouncycastle:bcpkix-jdk15on:1.64"
这会导致:lint
任务引发处理错误:
Which cause the :lint
task to throw processing errors:
> Task :mobile:lint
Error processing bcpkix-jdk15on-1.64.jar:META-INF/versions/9/module-info.class: broken class file? (This feature requires ASM6)
Error processing bcprov-jdk15on-1.64.jar:META-INF/versions/9/module-info.class: broken class file? (This feature requires ASM6)
META-INF/versions/9/module-info.class:损坏的类文件?(此功能需要ASM6)
同样适用于:
// https://mvnrepository.com/artifact/com.google.code.gson/gson
implementation "com.google.code.gson:gson:2.8.6"
由于从 1.4.1
升级到了 1.4.2-native-mt
,因此再次相同:
Since upgrading from 1.4.1
to 1.4.2-native-mt
, it's the same again:
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.4.2-native-mt"
kotlin-stdlib-1.4.0.jar:META-INF \ versions \ 9 \ module-info.class:损坏的类文件?(模块需要ASM6)
kotlin-stdlib-1.4.0.jar:META-INF\versions\9\module-info.class: broken class file? (Module requires ASM6)
推荐答案
在使用旧版本(可能使用Java 8构建)时,不会出现此类处理错误:
When using old versions (likely built with Java 8), there are no such processing errors:
// https://mvnrepository.com/artifact/org.bouncycastle
implementation "org.bouncycastle:bcprov-jdk15on:1.60"
implementation "org.bouncycastle:bcpkix-jdk15on:1.60"
// https://mvnrepository.com/artifact/com.google.code.gson/gson
implementation "com.google.code.gson:gson:2.8.5"
该问题显然是在 1.61
/ 2.8.6
版本(可能是用Java 9构建的)中引入的.
The issue obviously was introduced with version 1.61
/ 2.8.6
(likely built with Java 9).
当Google将答案带回自己的答案时,这很烦人.这并不是真正的答案.
It's annoying when Google brings one back to the own answer, which is not really an answer.
我写了一个 DeleteModuleInfoTask
和一个shell脚本,而不是保留版本或编辑JAR,它们自动从中删除了 module-info.class
任何给定的Java依赖项.
由于 commandLine
仅接受一条命令,因此几乎必须调用一个脚本.
而且我相信这应该是自定义 Exec
任务脚本的一个很好的例子.
Instead of keeping back the version or editing the JAR, I've wrote a DeleteModuleInfoTask
and a shell script, which automate the deletion of module-info.class
from any given Java dependency.
Since commandLine
only accepts a single command, one almost has to call a script.
And I believe this should serve as a good example for custom Exec
task scripting.
文件 module_info.sh
考虑 versions/9/module-info.class
和 module-info.class
:
#!/usr/bin/env bash
GRADLE_CACHE_DIR=$HOME/.gradle/caches/modules-2/files-2.1
ZIP_PATHS=(META-INF\versions\9\module-info.class versions/9/module-info.class module-info.class)
if [[ $# -ne 3 ]]; then
echo "Illegal number of parameters"
exit 1
else
if [ -d "$GRADLE_CACHE_DIR" ]; then
DIRNAME=${GRADLE_CACHE_DIR}/$1/$2/$3
if [ -d "$DIRNAME" ]; then
cd ${DIRNAME} || exit 1
find . -name ${2}-${3}.jar | (
read ITEM;
for ZIP_PATH in "${ZIP_PATHS[@]}"; do
INFO=$(zipinfo ${ITEM} ${ZIP_PATH} 2>&1)
if [ "${INFO}" != "caution: filename not matched: ${ZIP_PATH}" ]; then
zip ${ITEM} -d ${ZIP_PATH} # > /dev/null 2>&1
fi
done
)
exit 0
fi
fi
fi
文件 module_info.bat
取决于 7-Zip :>
File module_info.bat
depends on 7-Zip:
@echo off
for /R %USERPROFILE%\.gradle\caches\modules-2\files-2.1\%1\%2\%3\ %%G in (%2-%3.jar) do (
if exist %%G (
7z d %%G META-INF\versions\9\module-info.class > NUL:
7z d %%G versions\9\module-info.class > NUL:
7z d %%G module-info.class > NUL:
)
)
文件 tasks.gradle
提供了 DeleteModuleInfoTask
,该代码调用了两个CLI脚本之一:
File tasks.gradle
provides the DeleteModuleInfoTask
, which calls either of the two CLI scripts:
import javax.inject.Inject
abstract class DeleteModuleInfoTask extends Exec {
@Inject
DeleteModuleInfoTask(String dependency) {
def os = org.gradle.internal.os.OperatingSystem.current()
def stdout = new ByteArrayOutputStream()
def stderr = new ByteArrayOutputStream()
ignoreExitValue true
standardOutput stdout
errorOutput stderr
workingDir "${getProject().getGradle().getGradleUserHomeDir()}${File.separator}caches${File.separator}modules-2${File.separator}files-2.1${File.separator}${dependency.replace(":", File.separator).toString()}"
String script = "${getProject().getRootDir().getAbsolutePath()}${File.separator}scripts${File.separator}"
def prefix = ""; def suffix = "sh"
if (os.isWindows()) {prefix = "cmd /c "; suffix = "bat"}
String[] item = dependency.split(":")
commandLine "${prefix}${script}module_info.${suffix} ${item[0]} ${item[1]} ${item[2]}".split(" ")
doLast {
if (execResult.getExitValue() == 0) {
if (stdout.toString() != "") {
println "> Task :${project.name}:${name} ${stdout.toString()}"
}
} else {
println "> Task :${project.name}:${name} ${stderr.toString()}"
}
}
}
}
示例用法:
// Bouncycastle
tasks.register("lintFixModuleInfoBcPkix", DeleteModuleInfoTask, "org.bouncycastle:bcpkix-jdk15on:1.64")
lint.dependsOn lintFixModuleInfoBcPkix
tasks.register("lintFixModuleInfoBcProv", DeleteModuleInfoTask, "org.bouncycastle:bcprov-jdk15on:1.64")
lint.dependsOn lintFixModuleInfoBcProv
// GSON
tasks.register("lintFixModuleInfoGson", DeleteModuleInfoTask, "com.google.code.gson:gson:2.8.6")
lint.dependsOn lintFixModuleInfoGson
// Kotlin Standard Library
tasks.register("lintFixModuleInfoKotlinStdLib", DeleteModuleInfoTask, "org.jetbrains.kotlin:kotlin-stdlib:1.4.20")
lint.dependsOn lintFixModuleInfoKotlinStdLib
远程构建时,可能没有其他方法可以消除警告.
There probably is no other way to get rid of the warning when building remotely.
这篇关于META-INF/versions/9/module-info.class:损坏的类文件?(此功能需要ASM6)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!