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

首次创建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.

React Native 0.67 officially supports Java 8 or 11, so this is the most stable fix:

  1. Install OpenJDK 11 on your M1 Mac using Homebrew:
    brew install openjdk@11
    
  2. Update your shell config (.zshrc since you're using zsh) to set Java 11 as the default:
    Open ~/.zshrc in 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"
    
  3. Refresh your terminal session to apply the changes:
    source ~/.zshrc
    
  4. Verify the Java version is now 11.x:
    java -version
    
  5. 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:

  1. Open your project's android/gradle.properties file.
  2. 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
    
  3. 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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.04.28 13:32:30