Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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. 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

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.

like image 339
Keannylen Avatar asked Aug 03 '19 13:08

Keannylen


People also ask

Will install React Native 0.60 6 which is a breaking change?

For 0.60, React Native has been migrated over to AndroidX. This is a breaking change, and your native code and dependencies will need to be migrated as well. With this change, React Native apps will need to begin using AndroidX themselves.

How do I install latest version of React Native?

Visit the web page https://developer.android.com/studio/ and download android studio. After downloading the installation file of it, double click on it and proceed with the installation.

Does React Native support Android 11?

React Native App supports only 400 Android devices and Android 11 or + - Stack Overflow.


3 Answers

For those who are here for 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.

So For MacOS,

cd /Library/Java/JavaVirtualMachines
ls
  • Check the available JDKs

  • Remove the jdk-16 if present using this, 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.

like image 119
Shreyansh Avatar answered Oct 11 '22 22:10

Shreyansh


In this file android/gradle/wrapper/gradle-wrapper.properties change distributionUrl on this distributionUrl=https://services.gradle.org/distributions/gradle-6.0-all.zip

like image 3
Slava Vasilenko Avatar answered Oct 11 '22 20:10

Slava Vasilenko


Looks like Gradle is currently erroring on builds using openJDK-13.

Here's a Github issue thread.

Check the version of Java and JDK versions on your system by running the following command on in your terminal:

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.

Check this link for downgrading steps.

like image 2
Nishant Nair Avatar answered Oct 11 '22 21:10

Nishant Nair