跳到主要内容
新架构实战课 实操 + 基建 + 原理全维度包揽,抢先掌握 React Native 新架构精髓 立即查看 >Version: 0.70

Troubleshooting

注意

本文档内容仍处于实验阶段,内容会随着版本的迭代进行修改。您可随时在我们的工作组的讨论区发送反馈。 此外,本文档还包含了若干需手动配置的步骤,但这不代表新架构稳定版的最终开发体验。我们仍在开发相关的工具、模板和第三方库,帮助你更快地迁移到新架构上,而非从头开始配置环境。

This page contains resolutions to common problem you might face when migrating to the New Architecture.

Xcode Build Issues

Should the XCode Build fail with:

Command PhaseScriptExecution failed with a nonzero exit code

This error indicates that the codegen script that is injected into the Xcode build pipeline has exited early. You may get this for either your own library, or one of the core RN libraries (FBReactNativeSpec, rncore).

Open ~/Library/Developer/Xcode/DerivedData. and look for a folder named after your Xcode workspace (“RNTesterPods-AAAA” where “AAAA” is a string of characters). Within that folder, go to Build → Intermediates.noindex → Pods.build → Debug-iphonesimulator (or the equivalent for your iOS device, if applicable). Inside, look for the folder named after the codegen library has the script error. The logs for the script phase can be found within the DerivedSources folder, in a file named codegen-LibraryName.log. This log output should provide clarity on the source of the error.

CocoaPods and Node Reset

The CocoaPods integration will see frequent updates as we rollout the New Architecture, and it is possible to end up with your workspace in a broken state after one of these changes. You may clean up any changes related to the codegen by performing some of these steps:

  1. Run pod deintegrate in your ios directory (or wherever your Podfile is located) and re-run pod install (or arch -x86_64 pod install, in case of a Mac M1).
  2. Delete Podfile.lock and re-run pod install (or arch -x86_64 pod install, in case of a Mac M1).
  3. Delete node_modules and re-run yarn install.
  4. Delete your codegen artifacts and re-run pod install (or arch -x86_64 pod install, in case of a Mac M1), then clean and build your Xcode project.

Folly Version

As it happens, the Folly version used in your podspec must match whatever version is used in React Native at this time. If you see the following error after running pod install:

[!] CocoaPods could not find compatible versions for pod "RCT-Folly":

...you may have a version-mismatch. Take a look at your node_modules/react-native/React/FBReactNativeSpec/FBReactNativeSpec.podspec file and make note of the folly_version used there. Go back to your own podspec and set your folly_version to match.

Android build is failing with OutOfMemoryException

If your Android Gradle builds are failing with: OutOfMemoryException: Out of memory: Java heap space. or similar errors related to low memory, you might need to increase the memory allocated to the JVM.

You can do that by editing the gradle.properties file in your android/gradle.properties folder:

 # Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.
# Default value: -Xmx1024m -XX:MaxPermSize=256m
-# org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
+org.gradle.jvmargs=-Xmx4g -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8

Make sure to uncomment the line and set the preferred memory size with the -Xmx parameter. 2Gb should be the minimum required and 4Gb is recommended.

Android NDK and Mac with M1 Apple Silicon CPUs

We're aware of a series of incompatibilities between the Android NDK and Macs on M1 CPUs (here and here). As you need to enable the NDK when building from source, you might face problems during your build.

The workaround at this stage is suggested here. As newer version of the Android SDK/NDK are released, we will update the documentation with the necessary steps.