You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

MacOS环境下运行React Native Android项目Gradle编译报错求助

Fixing "Unsupported class file major version 61" in React Native's yarn android Build

Hey there! Let's get this Gradle error sorted out for you. That "major version 61" error is a super common Java/Gradle compatibility hiccup—here's what's going on and how to fix it:

What's Causing This?

Class file major version 61 corresponds to Java 17, and your current Gradle version doesn't support it. Gradle has strict compatibility rules with Java versions; older Gradle releases can't handle newer Java runtime files, which is exactly what's happening here.

Solution 1: Downgrade Java to a Version Supported by Your Gradle

If you're using an older React Native version (pre-0.70) or haven't updated Gradle yet, this is the most straightforward fix:

  • First, check your current Java version:
    java -version
    
  • Install Java 11 (it's a stable, widely supported version for most React Native projects pre-0.70)
  • Switch your system's Java environment to use Java 11:
    • On macOS/Linux: Set the JAVA_HOME environment variable temporarily with:
      export JAVA_HOME=/path/to/your/java11/installation
      
      (Or use a version manager like sdkman to switch permanently for all projects)
    • On Windows: Update the JAVA_HOME system environment variable to point to your Java 11 installation folder
  • Run yarn android again—this should resolve the compatibility issue right away

Solution 2: Upgrade Gradle to Support Java 17

If you want to keep using Java 17 (perfect for newer React Native versions like 0.70+), you'll need to upgrade your Gradle setup:

  1. Open android/gradle/wrapper/gradle-wrapper.properties
  2. Update the distributionUrl to a Gradle version that supports Java 17 (Gradle 7.3 or later works great). For example:
    distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-all.zip
    
  3. Open android/build.gradle and update the Android Gradle Plugin to match your new Gradle version. For Gradle 7.5, use plugin version 7.4.2:
    dependencies {
        classpath("com.android.tools.build:gradle:7.4.2")
        // ... keep your other dependencies here
    }
    
  4. Let Gradle sync the project (it'll download the new version automatically), then run yarn android again

Quick Check: React Native Version Compatibility

Just a heads-up to make sure your setup aligns with your RN version:

  • React Native 0.70+: Supports Java 17 and requires Gradle 7.3+
  • React Native 0.68-0.69: Works best with Java 11 and Gradle 7.x
  • Older RN versions: Stick to Java 8/11 and their matching Gradle versions

内容的提问来源于stack exchange,提问作者David Odinaka Enyoghasim

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.01 02:02:32