简体   繁体   English

升级到 react-native 版本 0.60.4 后 react-native run-android 出错

[英]Error with react-native run-android after upgrade to react-native version 0.60.4

I am upgrading react-native from 0.59.5 to 0.60.4 with my existing application.我正在使用我现有的应用程序将 react-native 从 0.59.5 升级到 0.60.4。 But facing a problem as below但面临如下问题

* 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

And my build.gradle is我的 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
            }
        }
    }

I have absolutely no clue what this error is about and could not find much helpful articles.我完全不知道这个错误是关于什么的,也找不到太多有用的文章。 Please help me out.请帮帮我。

For those who are here for java.lang.IllegalArgumentException: Unsupported class file major version 60对于那些在这里为java.lang.IllegalArgumentException: Unsupported class file major version 60的人

One of the reason for the same is:原因之一是:

Java version 16 installed which is not yet supported by react-native.已安装 Java 版本 16,但 react-native 尚不支持。

So For MacOS,所以对于 MacOS,

cd /Library/Java/JavaVirtualMachines
ls
  • Check the available JDKs检查可用的 JDK

  • Remove the jdk-16 if present using this, sudo rm -rf jdk-16.jdk/删除 jdk-16(如果存在),使用sudo rm -rf jdk-16.jdk/

Basically, you can remove JDKs other than adoptopenjdk-8.jdk which will be present if you followed React-Native Env Setup .基本上,您可以删除除adoptopenjdk-8.jdk之外的 JDK,如果您遵循React-Native Env Setup将会出现这些 JDK。

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

Looks like Gradle is currently erroring on builds using openJDK-13.看起来 Gradle 目前在使用 openJDK-13 构建时出错。

Here's a Github issue thread.这是一个Github 问题线程。

Check the version of Java and JDK versions on your system by running the following command on in your terminal:通过在终端中运行以下命令来检查系统上的 Java 和 JDK 版本:

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

OR或者

file `which java javac`

This will list the current installations on your system.这将列出您系统上的当前安装。 If you see openjdk-13 anywhere, you'll have to downgrade to openjdk-8 .如果您在任何地方看到openjdk-13 ,则必须降级到openjdk-8

Check this link for downgrading steps.检查此链接以了解降级步骤。

Also, you can use this super lightweight utility jEnv to manage multiple versions of Java on your machine.此外,您可以使用这个超级轻量级​​的实用程序jEnv来管理您机器上的多个 Java 版本。 I've used it for many years with good results.我已经使用了很多年,效果很好。

$ jenv add /usr/lib/jvm/java-8-openjdk-amd64/
openjdk64-1.8.0.292 added
1.8.0.292 added
1.8 added

$ jenv add /usr/lib/jvm/java-16-openjdk-amd64/
openjdk64-16.0.1 added
16.0.1 added
16.0 added
16 added

Then place a file at android/.java-version with the contents:然后在android/.java-version放置一个文件,内容如下:

1.8

Answer : .答案:

Activity.main活动主

Toast.makeText(this, "Your message, Toast.LENGTH_SHORT).show();

checkout the output检查输出

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在Ubuntu 14上运行“ react-native run-android”时出错 - Error Running 'react-native run-android' on ubuntu 14 react-native run-android 构建错误 &#39;:app:generateDebugBuildConfig&#39; - react-native run-android Building Error ':app:generateDebugBuildConfig' 在运行react-native run-android时发生错误react native - Error react native when run react-native run-android npx react-native run-android 错误 > 任务:react-native-gradle-plugin:compileKotlin FAILED - npx react-native run-android error > Task :react-native-gradle-plugin:compileKotlin FAILED react-native run-android 不起作用:/ - react-native run-android does not work :/ react-native run-android因错误而失败:任务执行失败':app:dexDebug' - react-native run-android failed with error: Execution failed for task ':app:dexDebug' react-native run-android 错误“任务:app:javaPreCompileDebug FAILED” - react-native run-android error "Task :app:javaPreCompileDebug FAILED" 在本地运行Android期间安装Gradle时出现SSL错误 - SSL error when installing Gradle during react-native run-android 运行react-native run-android时,在MainActivity.java上出错 - Getting error on MainActivity.java when running react-native run-android 当我在终端命令的 react-native 中启动 npx react-native run-android 时,这个问题来了 - When i start npx react-native run-android in my react-native in terminal command this issue is coming
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM