升级到React-native版本0.60.4后,react-native run-android错误

时间:2019-08-03 13:55:44

标签: java android react-native gradle android-gradle-plugin

我将现有应用程序从0.59.5升级到0.60.4。但是面临如下问题

* Where:
Build file '/home/bingl/Projects/blackstar/frontend/android/app/build.gradle'

* What went wrong:
Could not compile build file '/home/bingl/Projects/blackstar/frontend/android/app/build.gradle'.
> 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(ClassNodeReso

我的build.gradle是

android {
    compileSdkVersion 28
    buildToolsVersion "28.0.3"

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    defaultConfig {
        applicationId "com.frontend"
        minSdkVersion 16
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
    }
    splits {
        abi {
            reset()
            enable enableSeparateBuildPerCPUArchitecture
            universalApk false  // If true, also generate a universal APK
            include "armeabi-v7a", "x86", "arm64-v8a", "x86_64"
        }
    }
    buildTypes {
        release {
            minifyEnabled enableProguardInReleaseBuilds
            proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
        }
    }
    // applicationVariants are e.g. debug, release
    applicationVariants.all { variant ->
        variant.outputs.each { output ->
            // For each separate APK per architecture, set a unique version code as described here:
            // http://tools.android.com/tech-docs/new-build-system/user-guide/apk-splits
            def versionCodes = ["armeabi-v7a":1, "x86":2, "arm64-v8a": 3, "x86_64": 4]
            def abi = output.getFilter(OutputFile.ABI)
            if (abi != null) {  // null for the universal-debug, universal-release variants
                output.versionCodeOverride =
                        versionCodes.get(abi) * 1048576 + defaultConfig.versionCode
            }
        }
    }

我完全不知道此错误是什么,也找不到太多有用的文章。请帮帮我。

3 个答案:

答案 0 :(得分:2)

对于那些在这里java.lang.IllegalArgumentException: Unsupported class file major version 60

同样的原因之一是:

已安装 Java 版本 16,但 react-native 尚不支持。

所以对于 MacOS,

cd /Library/Java/JavaVirtualMachines
ls
  • 检查可用的 JDK

  • 删除 jdk-16(如果存在), sudo rm -rf jdk-16.jdk/

基本上,您可以删除 adoptopenjdk-8.jdk 以外的 JDK,如果您遵循 React-Native Env Setup,它将出现。

答案 1 :(得分:0)

在此文件android/gradle/wrapper/gradle-wrapper.properties中更改此distributionUrl=https\://services.gradle.org/distributions/gradle-6.0-all.zip上的distributionUrl

答案 2 :(得分:-1)

看起来Gradle当前在使用openJDK-13的构建中出错。

这里是Github issue线程。

通过在终端上运行以下命令来检查系统上的Java和JDK版本:

file /etc/alternatives/java /etc/alternatives/javac

OR

file `which java javac`

这将列出系统上的当前安装。如果您在任何地方都看到openjdk-13,则必须降级到openjdk-8

选中此link进行降级步骤。