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

React Native技术求助:MainApplication.java报‘new architecture doesn't exist’错误

Fixing "new architecture doesn't exist" & MainApplication.java Errors on M1 Mac Pro

Hey there, let's tackle this issue step by step. The "new architecture doesn't exist" error paired with other issues in MainApplication.java usually stems from misconfiguration around React Native's New Architecture—especially tricky on M1 chips which have specific build quirks. Here’s what you can try:

1. Verify React Native Version & New Architecture Compatibility

First, confirm your React Native version to rule out compatibility gaps:

react-native --version

The New Architecture is only fully supported starting from React Native 0.68. If your version is older, you have two clear options:

  • Upgrade to a newer RN version (follow the official upgrade workflow tailored to your current version)
  • Disable the New Architecture entirely (the quicker fix if you don’t need its features right now)

2. Disable New Architecture (If Not Needed)

Most likely, the errors pop up because the New Architecture flag was enabled but your environment isn’t properly set up for it. Let’s turn it off:

  • Open android/gradle.properties and ensure this line is present and set to false:
    newArchEnabled=false
    
  • Clean your Android project’s build cache specifically (this step is often missing from general cache resets):
    cd android && ./gradlew clean
    
  • Re-run your full cache cleanup commands for good measure:
    react-native start --reset-cache
    watchman watch-del-all
    rm -rf ~/.gradle/caches/
    

3. Fix M1-Specific Build Configuration

M1 chips require extra JVM arguments to avoid build conflicts. Update your android/gradle.properties with these lines:

org.gradle.jvmargs=-Xmx2048m --add-exports=java.base/sun.nio.ch=ALL-UNNAMED --add-opens=java.base/java.lang=ALL-UNNAMED --add-opens=java.base/java.lang.reflect=ALL-UNNAMED --add-opens=java.base/java.io=ALL-UNNAMED --add-exports=jdk.unsupported/sun.misc=ALL-UNNAMED
android.bundle.enableUncompressedNativeLibs=false

If you ever plan to use the New Architecture later, ensure your Android SDK has NDK 25+ installed—but for now, disabling the New Architecture will bypass this requirement.

4. Clean Up MainApplication.java

If your MainApplication.java includes New Architecture-related code (like imports for DefaultNewArchitectureEntryPoint), remove those lines to revert to the standard setup. A basic, working MainApplication.java should look something like this (adjust package names to match your project):

package com.yourprojectname;

import android.app.Application;
import com.facebook.react.PackageList;
import com.facebook.react.ReactApplication;
import com.facebook.react.ReactNativeHost;
import com.facebook.react.ReactPackage;
import com.facebook.react.defaults.DefaultReactNativeHost;
import com.facebook.soloader.SoLoader;
import java.util.List;

public class MainApplication extends Application implements ReactApplication {

  private final ReactNativeHost mReactNativeHost =
      new DefaultReactNativeHost(this) {
        @Override
        public boolean getUseDeveloperSupport() {
          return BuildConfig.DEBUG;
        }

        @Override
        protected List<ReactPackage> getPackages() {
          List<ReactPackage> packages = new PackageList(this).getPackages();
          // Add manually linked packages here if needed
          return packages;
        }

        @Override
        protected String getJSMainModuleName() {
          return "index";
        }
      };

  @Override
  public ReactNativeHost getReactNativeHost() {
    return mReactNativeHost;
  }

  @Override
  public void onCreate() {
    super.onCreate();
    SoLoader.init(this, /* native exopackage */ false);
  }
}

Make sure to remove any references to isNewArchEnabled() or DefaultNewArchitectureEntryPoint.load() if you’ve disabled the New Architecture.

5. Rebuild the Project

Finally, rebuild your Android project to apply all changes:

react-native run-android

Or run the assemble command directly from the Android folder for more verbose output:

cd android && ./gradlew assembleDebug

Extra Tips

  • Double-check that your Android SDK paths are correctly set in ~/.bash_profile or ~/.zshrc (M1 sometimes uses different paths for Rosetta vs native execution)
  • If you’re using Rosetta to run Android Studio, ensure your terminal is also running under Rosetta when executing build commands

内容的提问来源于stack exchange,提问作者REINA

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.04.28 18:02:34