android启动问题。不支持的班级文件主要版本57

时间:2019-10-11 17:22:35

标签: react-native

我已经按照mac android入门,但是当我运行android时,它失败并出现以下错误。我试图在线找到答案,但似乎找不到解决方案。香港专业教育学院确保我在机器上安装了正确的Java JDK8,但即时通讯仍然收到此错误。任何意见是极大的赞赏!

> startup failed:
  General error during semantic analysis: Unsupported class file major version 57

  java.lang.IllegalArgumentException: Unsupported class file major version 57
        at groovyjarjarasm.asm.ClassReader.<init>(ClassReader.java:184)
        at groovyjarjarasm.asm.ClassReader.<init>(ClassReader.java:166)
        at groovyjarjarasm.asm.ClassReader.<init>(ClassReader.java:152)
        at groovyjarjarasm.asm.ClassReader.<init>(ClassReader.java:273)
        at org.codehaus.groovy.ast.decompiled.AsmDecompiler.parseClass(AsmDecompiler.java:81)
        at org.codehaus.groovy.control.ClassNodeResolver.findDecompiled(ClassNodeResolver.java:254)
        at org.codehaus.groovy.control.ClassNodeResolver.tryAsLoaderClassOrScript(ClassNodeResolver.java:192)
        at org.codehaus.groovy.control.ClassNodeResolver.findClassNode(ClassNodeResolver.java:172)
        at org.codehaus.groovy.control.ClassNodeResolver.resolveName(ClassNodeResolver.java:128)
        at org.codehaus.groovy.ast.decompiled.AsmReferenceResolver.resolveClassNullable(AsmReferenceResolver.java:59)
        at org.codehaus.groovy.ast.decompiled.AsmReferenceResolver.resolveClass(AsmReferenceResolver.java:46)
        at org.codehaus.groovy.ast.decompiled.AsmReferenceResolver.resolveNonArrayType(AsmReferenceResolver.java:81)
        at org.codehaus.groovy.ast.decompiled.AsmReferenceResolver.resolveType(AsmReferenceResolver.java:72)
        at org.codehaus.groovy.ast.decompiled.MemberSignatureParser.createMethodNode(MemberSignatureParser.java:55)
        at org.codehaus.groovy.ast.decompiled.DecompiledClassNode.lazyInitMembers(DecompiledClassNode.java:195)
        at org.codehaus.groovy.ast.decompiled.DecompiledClassNode.getDeclaredMethods(DecompiledClassNode.java:121)
        at org.codehaus.groovy.ast.ClassNode.getMethods(ClassNode.java:912)
        at org.codehaus.groovy.ast.ClassNode.tryFindPossibleMethod(ClassNode.java:1280)
        at org.codehaus.groovy.control.StaticImportVisitor.transformMethodCallExpression(StaticImportVisitor.java:252)
        at org.codehaus.groovy.control.StaticImportVisitor.transform(StaticImportVisitor.java:112)
        at org.codehaus.groovy.ast.ClassCodeExpressionTransformer.visitExpressionStatement(ClassCodeExpressionTransformer.java:144)
        at org.codehaus.groovy.ast.stmt.ExpressionStatement.visit(ExpressionStatement.java:42)
        at org.codehaus.groovy.ast.ClassCodeVisitorSupport.visitClassCodeContainer(ClassCodeVisitorSupport.java:110)
        at org.codehaus.groovy.ast.ClassCodeVisitorSupport.visitConstructorOrMethod(ClassCodeVisitorSupport.java:121)
        at org.codehaus.groovy.ast.ClassCodeExpressionTransformer.visitConstructorOrMethod(ClassCodeExpressionTransformer.java:55)
        at org.codehaus.groovy.control.StaticImportVisitor.visitConstructorOrMethod(StaticImportVisitor.java:88)
        at org.codehaus.groovy.ast.ClassCodeVisitorSupport.visitConstructor(ClassCodeVisitorSupport.java:128)
        at org.codehaus.groovy.ast.ClassNode.visitContents(ClassNode.java:1099)
        at org.codehaus.groovy.ast.ClassCodeVisitorSupport.visitClass(ClassCodeVisitorSupport.java:54)
        at org.codehaus.groovy.control.StaticImportVisitor.visitClass(StaticImportVisitor.java:82)
        at org.codehaus.groovy.control.CompilationUnit$14.call(CompilationUnit.java:717)
        at org.codehaus.groovy.control.CompilationUnit.applyToPrimaryClassNodes(CompilationUnit.java:1095)
        at org.codehaus.groovy.control.CompilationUnit.doPhaseOperation(CompilationUnit.java:649)
        at org.codehaus.groovy.control.CompilationUnit.processPhaseOperations(CompilationUnit.java:627)
        at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:604)
        at groovy.lang.GroovyClassLoader.doParseClass(GroovyClassLoader.java:390)
        at groovy.lang.GroovyClassLoader.access$300(GroovyClassLoader.java:89)
        at groovy.lang.GroovyClassLoader$5.provide(GroovyClassLoader.java:330)
        at groovy.lang.GroovyClassLoader$5.provide(GroovyClassLoader.java:327)
        at org.codehaus.groovy.runtime.memoize.ConcurrentCommonCache.getAndPut(ConcurrentCommonCache.java:147)
        at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:325)
        at org.gradle.groovy.scripts.internal.DefaultScriptCompilationHandler.compileScript(DefaultScriptCompilationHandler.java:133)
        at org.gradle.groovy.scripts.internal.DefaultScriptCompilationHandler.compileToDir(DefaultScriptCompilationHandler.java:93)
        at org.gradle.groovy.scripts.internal.BuildOperationBackedScriptCompilationHandler$2.run(BuildOperationBackedScriptCompilationHandler.java:54)
        at org.gradle.internal.operations.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:402)
        at org.gradle.internal.operations.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:394)
        at org.gradle.internal.operations.DefaultBuildOperationExecutor$1.execute(DefaultBuildOperationExecutor.java:165)
        at org.gradle.internal.operations.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:250)
        at org.gradle.internal.operations.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:158)
        at org.gradle.internal.operations.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:92)
        at org.gradle.internal.operations.DelegatingBuildOperationExecutor.run(DelegatingBuildOperationExecutor.java:31)
        at org.gradle.groovy.scripts.internal.BuildOperationBackedScriptCompilationHandler.compileToDir(BuildOperationBackedScriptCompilationHandler.java:51)

Dev环境: Mac OS X 10.15

7 个答案:

答案 0 :(得分:6)

要解决此错误,我进入了 android / gradle / wrapper / gradle-wrapper.properties 文件,并将distributionUrl(设置为 gradle-5.5 )修改为 gradle-6.0 。由于某种原因,它不能识别6.2发行版,即使这是我当前使用的gradle版本。我认为这应该与版本相对应,但显然不符合。

之前: distributionUrl = https://services.gradle.org/distributions/gradle-5.5-all.zip

之后: distributionUrl = https://services.gradle.org/distributions/gradle-6.0-all.zip

让我知道这是否对您有用。

答案 1 :(得分:5)

运行gradle build时遇到同样的问题。根据Google和github的搜索。我发现gradle当前版本(5.xx)不支持jdk13。最后,6.x版本支持它,但尚未发布,因此我必须将jdk版本降级为12.x。

将Java降级到12 https://www.jverdeyen.be/mac/downgrade-brew-cask-application/

brew cask uninstall adoptopenjdk # uninstall jdk version 13.x
brew cask install https://raw.githubusercontent.com/caskroom/homebrew-cask/025e5b6c3ad66ac2a2da75abb91d109d68dd4f6d/Casks/adoptopenjdk.rb

答案 2 :(得分:4)

这是因为您的JDK版本不支持您的项目的Gradle版本。 jdk-13不支持Gradle 5。最佳解决方案是在gradle-wrapper.properties中更改您的gradle版本。您可以设置晚于6的任何gradle版本,

(在Mac上)转到“首选项”>“构建,执行,部署> Gradle”

(Windows)File> Settings> Build,Execution,Deployment> Gradle

然后在Gradle部分下,您可以选择Gradle和Java,如下图所示enter image description here

您还可以单独安装gradle并使用指定的路径。但是,我建议您将gradle-wrapper.properties文件和Gradle JVM用于内部JDK或Project JVM。这样,您不必卸载JDK 13并安装降级的JDK11或JDK12

如果您在Android Studio中找不到此选项,请降级JDK或使用第一个选项。

答案 3 :(得分:1)

如果您不想降级JDK发行版,则可以使用gradle包装器的快照之一,这似乎对很多人都有用(对我而言)

解决方案的来源:https://github.com/gradle/gradle/issues/8681#issuecomment-524039994

要使用快照,请选择以下可用文件之一:https://services.gradle.org/distributions-snapshots/,转到您的PROJECT_ROOT/gradle/wrapper/gradle-wrapper.properties文件,然后将zip文件地址设置为distributibutionUrl

答案 4 :(得分:0)

我从AdoptOpenJDK 13升级到14,我的Android项目现在成功构建。

答案 5 :(得分:0)

我按照Okta Spring Security Authentication Example中所述进行./gradlew bootRun搜索后发现此错误,因此我进入了此页面。确实,我在Ubuntu 20上安装了OpenJDK13:

$ java --version
openjdk 13.0.3 2020-04-14
OpenJDK Runtime Environment (build 13.0.3+3-Ubuntu-1ubuntu2)
OpenJDK 64-Bit Server VM (build 13.0.3+3-Ubuntu-1ubuntu2, mixed mode)

我不喜欢降级Java版本的想法,所以我upgraded Gradlerebuilt gradlew,这是针对项目的wrapper。在尝试此解决方案之前,请确保您正在使用版本控制或对当前项目进行备份

这些步骤是:

1)安装skdkman以轻松安装gradle。使用apt install给了我一个古老的版本。

curl -s "https://get.sdkman.io" | bash
source "$HOME/.sdkman/bin/sdkman-init.sh"

2)检查 sdkman 是否正确安装

sdk version

3)安装gradle 6

sdk install gradle 6.5

4)在同一目录上重建gradlew

gradle wrapper

5)运行应用程序

./gradlew bootRun

您应该看到类似这样的内容:

Downloading https://services.gradle.org/distributions/gradle-6.5-bin.zip
.........10%..........20%..........30%..........40%.........50%..........60%..........70%..........80%.........90%..........100%

> Task :bootRun

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::        (v2.1.5.RELEASE)

执行git status显示许多文件已更改:

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
    modified:   gradle/wrapper/gradle-wrapper.jar
    modified:   gradle/wrapper/gradle-wrapper.properties
    modified:   gradlew
    modified:   gradlew.bat

为了方便使用,我将在自己的分支中提交这些更改。

答案 6 :(得分:0)

我的愚蠢错误是我没有在 shell 中加载配置。 React Native env setup 声明加载环境变量执行:

Type source $HOME/.bash_profile for bash or source $HOME/.zprofile to load the config into your current shell.

所以对我来说,env 文件位于根文件夹中。所以我不得不使用命令加载它们

$ source ~/.bash_profile