首次创建React Native项目执行yarn run-android时无法安装Android应用的问题求助
Fix for "Unable to make field private final java.lang.String java.io.File.path accessible" in React Native 0.67.2 (M1 Mac)
Let's break down what's happening here and how to fix it quickly:
Why this error happens
Your React Native 0.67.2 project uses an older version of Gradle that isn't compatible with Java 17. Java 9+ introduced a module system that restricts access to internal APIs like java.io.File.path, which the old Gradle version still relies on to process your app's manifest file.
Solution 1: Downgrade Java to 11 (Recommended)
React Native 0.67 officially supports Java 8 or 11, so this is the most stable fix:
- Install OpenJDK 11 on your M1 Mac using Homebrew:
brew install openjdk@11 - Update your shell config (
.zshrcsince you're using zsh) to set Java 11 as the default:
Open~/.zshrcin a text editor and add these lines:export JAVA_HOME="/opt/homebrew/opt/openjdk@11/libexec/openjdk.jdk/Contents/Home" export PATH="$JAVA_HOME/bin:$PATH" - Refresh your terminal session to apply the changes:
source ~/.zshrc - Verify the Java version is now 11.x:
java -version - Clean your Android build cache and re-run the app:
cd android && ./gradlew clean cd .. && yarn run-android
Solution 2: Configure Gradle to work with Java 17 (If you don't want to downgrade)
If you prefer to keep Java 17, you can add VM arguments to let Gradle access the restricted APIs:
- Open your project's
android/gradle.propertiesfile. - Add the following line to the file:
org.gradle.jvmargs=--add-opens java.base/java.io=ALL-UNNAMED --add-opens java.base/java.lang=ALL-UNNAMED --add-opens java.base/java.util=ALL-UNNAMED - Save the file, clean the build cache, and re-run:
cd android && ./gradlew clean cd .. && yarn run-android
Either of these methods should resolve the manifest processing error and let you install your Android app successfully.
内容的提问来源于stack exchange,提问作者Juno
相关产品推荐
相关产品推荐

