React Native run-android构建失败:UnsupportedClassVersionError问题求助
react-native run-android on Mac Hey there, let's break down this error you're hitting when trying to launch your React Native Android app. That UnsupportedClassVersionError: com/android/build/gradle/AppPlugin : Unsupported major.minor version 52.0 message is a clear hint: your system's Java version is too old for the Android Gradle plugin your project uses. Version 52.0 maps directly to Java 8 (JDK 1.8)—so your terminal is running an older JDK that can't load the plugin's classes properly.
Here's how to fix it step by step:
Step 1: Confirm your current Java version
First, check what JDK your terminal is using. Run this command:
java -version
If the output shows a version like 1.7.x or older, that's definitely the root cause.
Step 2: Install JDK 8 (if you don't have it)
On Mac, the easiest way to get JDK 8 is via Homebrew. Run this command in your terminal:
brew install adoptopenjdk/openjdk/adoptopenjdk8
Step 3: Switch your terminal to use JDK 8
You need to update your shell profile to set JDK 8 as the default for terminal sessions:
- For Bash users: Open your
~/.bash_profilefile in a text editor, add this line, then save:
Reload the profile to apply changes:export JAVA_HOME=$(/usr/libexec/java_home -v 1.8)source ~/.bash_profile - For Zsh users (default on macOS Catalina and newer): Open
~/.zshrc, add the same line above, save, then run:source ~/.zshrc
Step 4: Verify the switch worked
Run java -version again—you should see output confirming Java 1.8.x is now active.
Step 5: Re-run your React Native build
Now try launching your app again:
react-native run-android
This should resolve the version mismatch and let the build complete successfully.
Quick Extra Tips
If you still run into issues, double-check your project's android/build.gradle file to ensure the Gradle plugin version isn't requiring a newer JDK than 8 (most React Native projects targeting standard Android versions stick to JDK 8 compatibility). Also, if you use Android Studio to build, make sure its JDK setting (File > Project Structure > SDK Location > JDK Location) points to JDK 8 too.
内容的提问来源于stack exchange,提问作者Mudassar

