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

React Native更新依赖包后遇StackOverflowError无法运行求助

React Native依赖更新后本地构建失败问题

问题描述

更新React Native项目部分依赖包后,本地无法正常运行项目。同事更新后的代码在其他电脑上均可正常运行,但我的电脑始终失败。已尝试以下操作但问题依旧:

  • 删除node_modules、yarn.lock
  • 删除Android的build目录并执行gradlew clean
  • 完全删除项目后重新克隆安装

报错信息

CMake Warning at C:/Users/.../Local/Android/Sdk/ndk/23.1.7779620/build/cmake/android-legacy.toolchain.cmake:416 (message):
    An old version of CMake is being used that cannot automatically detect
    compiler attributes.  Compiler identification is being bypassed.  Some
    values may be wrong or missing.  Update to CMake 3.19 or newer to use
    CMake's built-in compiler identification.
  Call Stack (most recent call first):
    C:/Users/.../Local/Android/Sdk/ndk/23.1.7779620/build/cmake/android.toolchain.cmake:55 (include)
    .cxx/Debug/3ay5n6us/arm64-v8a/CMakeFiles/3.18.1-g262b901-dirty/CMakeSystem.cmake:6 (include)
    CMakeLists.txt:1 (project)


  ninja: error: manifest 'build.ninja' still dirty after 100 tries


* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
==============================================================================

2: Task failed with an exception.
-----------
* What went wrong:
java.lang.StackOverflowError (no error message)

* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
==============================================================================

* Get more help at https://help.gradle.org

BUILD FAILED in 13m 29s

    at makeError (C:\Users\...\node_modules\execa\index.js:174:9)
    at C:\Users\...\node_modules\execa\index.js:278:16
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async runOnAllDevices (C:\Users\...\node_modules\@react-native-community\cli-platform-android\build\commands\runAndroid\runOnAllDevices.js:82:7)
    at async Command.handleAction (C:\Users\...\node_modules\@react-native-community\cli\build\index.js:108:9)

项目Gradle配置(顶层build.gradle)

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    ext {
        buildToolsVersion = "33.0.0"
        minSdkVersion = 21
        compileSdkVersion = 33
        targetSdkVersion = 33

        // We use NDK 23 which has both M1 support and is the side-by-side NDK version from AGP.
        ndkVersion = "23.1.7779620"
    }
    repositories {
        google()
        mavenCentral()
        jcenter()
    }
    dependencies {
        classpath("com.android.tools.build:gradle:7.3.1")
        classpath("com.facebook.react:react-native-gradle-plugin")
        classpath 'com.google.gms:google-services:4.3.8'
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        configurations.all {
        resolutionStrategy {
            // Remove this override in 0.65+, as a proper fix is included in react-native itself.
            //force "com.facebook.react:react-native:" + REACT_NATIVE_VERSION
        }
        }

        google()
        mavenLocal()
        maven {
            // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
            url("$rootDir/../node_modules/react-native/android")
        }
        maven {
            // Android JSC is installed from npm
            url("$rootDir/../node_modules/jsc-android/dist")
        }

        maven { url 'https://www.jitpack.io' }
        jcenter()

        flatDir {
            dirs 'libs'
        }
    }
}

解决方案建议

  • 升级CMake版本:根据报错提示,当前使用的CMake版本低于3.19,无法自动识别编译器属性。打开Android Studio的SDK Manager,找到CMake选项,升级到3.19或更高版本。
  • 检查系统环境变量:确保CMake的路径已正确添加到系统环境变量中,避免Gradle调用旧版本的CMake。
  • 调整Gradle堆内存:java.lang.StackOverflowError可能是Gradle堆内存不足导致的。在项目根目录的gradle.properties文件中添加或修改:
    org.gradle.jvmargs=-Xmx4096m -XX:MaxPermSize=2048m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
    
  • 验证NDK版本一致性:确认本地安装的NDK版本与项目配置的ndkVersion = "23.1.7779620"完全一致,避免版本不匹配问题。
  • 清理CMake缓存:手动删除项目中.cxx目录(报错中提到的.cxx/Debug/3ay5n6us/arm64-v8a这类路径),然后重新执行构建。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.16 13:13:15