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

React Native Android构建失败:expo-modules-core CMake编译错误

React Native + Expo Android编译失败:expo-modules-core C++编译错误

错误日志

> Task :expo-modules-core:buildCMakeDebug[armeabi-v7a]
C/C++: ninja: Entering directory `/Users/abc/Documents/React_Native_Apps/app-new/node_modules/expo-modules-core/android/.cxx/Debug/131e2i41/armeabi-v7a'
C/C++: In file included from /Users/abc/Documents/React_Native_Apps/app-new/node_modules/expo-modules-core/android/src/main/cpp/JavaScriptModuleObject.cpp:3:
C/C++: In file included from /Users/abc/Documents/React_Native_Apps/app-new/node_modules/expo-modules-core/android/src/main/cpp/JavaScriptModuleObject.h:5:
C/C++: In file included from /Users/abc/.gradle/caches/transforms-3/af481f74ca2b61c91496ce7d7a53c1e7/transformed/jetified-fbjni-0.3.0/prefab/modules/fbjni/include/fbjni/fbjni.h:21:
C/C++: In file included from /Users/abc/.gradle/caches/transforms-3/af481f74ca2b61c91496ce7d7a53c1e7/transformed/jetified-fbjni-0.3.0/prefab/modules/fbjni/include/fbjni/detail/Environment.h:18:
C/C++: In file included from /Users/abc/Library/Android/sdk/ndk/25.2.9519653/toolchains/llvm/prebuilt/darwin-x86_64/sysroot/usr/include/c++/v1/functional:504:
C/C++: /Users/abc/Library/Android/sdk/ndk/25.2.9519653/toolchains/llvm/prebuilt/darwin-x86_64/sysroot/usr/include/c++/v1/memory:4434:5: error: static_assert failed due to requirement 'is_constructible<facebook::react::LongLivedObjectCollection>::value' "Can't construct object in make_shared"
C/C++: /Users/abc/Documents/React_Native_Apps/app-new/node_modules/expo-modules-core/android/src/main/cpp/JavaScriptModuleObject.cpp:238:37: note: in instantiation of function template specialization 'std::make_shared<facebook::react::LongLivedObjectCollection>' requested here
C/C++: In file included from /Users/abc/Documents/React_Native_Apps/app-new/node_modules/expo-modules-core/android/src/main/cpp/JavaScriptModuleObject.cpp:3:
C/C++: In file included from /Users/abc/Documents/React_Native_Apps/app-new/node_modules/expo-modules-core/android/src/main/cpp/JavaScriptModuleObject.h:5:
C/C++: In file included from /Users/abc/.gradle/caches/transforms-3/af481f74ca2b61c91496ce7d7a53c1e7/transformed/jetified-fbjni-0.3.0/prefab/modules/fbjni/include/fbjni/fbjni.h:21:
C/C++: In file included from /Users/abc/.gradle/caches/transforms-3/af481f74ca2b61c91496ce7d7a53c1e7/transformed/jetified-fbjni-0.3.0/prefab/modules/fbjni/include/fbjni/detail/Environment.h:18:
C/C++: In file included from /Users/abc/Library/Android/sdk/ndk/25.2.9519653/toolchains/llvm/prebuilt/darwin-x86_64/sysroot/usr/include/c++/v1/functional:504:
C/C++: /Users/jasminderpalsingh/Library/Android/sdk/ndk/25.2.9519653/toolchains/llvm/prebuilt/darwin-x86_64/sysroot/usr/include/c++/v1/memory:2260:46: error: field of type 'facebook::react::LongLivedObjectCollection' has private default constructor
C/C++: /Users/abc/Library/Android/sdk/ndk/25.2.9519653/toolchains/llvm/prebuilt/darwin-x86_64/sysroot/usr/include/c++/v1/memory:2353:42: note: in instantiation of member function 'std::__compressed_pair_elem<facebook::react::LongLivedObjectCollection, 1, false>::__compressed_pair_elem' requested here
C/C++: /Users/abc/Library/Android/sdk/ndk/25.2.9519653/toolchains/llvm/prebuilt/darwin-x86_64/sysroot/usr/include/c++/v1/memory:3628:12: note: in instantiation of function template specialization 'std::__compressed_pair<std::allocator<facebook::react::LongLivedObjectCollection>, facebook::react::LongLivedObjectCollection>::__compressed_pair<std::allocator<facebook::react::LongLivedObjectCollection>, std::__value_init_tag>' requested here
C/C++: /Users/abc/Library/Android/sdk/ndk/25.2.9519653/toolchains/llvm/prebuilt/darwin-x86_64/sysroot/usr/include/c++/v1/memory:4441:26: note: in instantiation of member function 'std::__shared_ptr_emplace<facebook::react::LongLivedObjectCollection, std::allocator<facebook::react::LongLivedObjectCollection>>::__shared_ptr_emplace' requested here
C/C++: /Users/abc/Documents/React_Native_Apps/app-new/node_modules/expo-modules-core/android/src/main/cpp/JavaScriptModuleObject.cpp:238:37: note: in instantiation of function template specialization 'std::make_shared<facebook::react::LongLivedObjectCollection>' requested here
C/C++: /Users/abc/.gradle/caches/transforms-3/05f8c5110695b559e432038ccd78233f/transformed/jetified-react-android-0.72.0-debug/prefab/modules/react_nativemodule_core/include/react/bridging/LongLivedObject.h:52:3: note: declared private here
C/C++: /Users/abc/Documents/React_Native_Apps/app-new/node_modules/expo-modules-core/android/src/main/cpp/MethodMetadata.cpp:40:57: error: too many arguments to function call, expected 3, have 4
C/C++: /Users/abc/.gradle/caches/transforms-3/05f8c5110695b559e432038ccd78233f/transformed/jetified-react-android-0.72.0-debug/prefab/modules/react_nativemodule_core/include/react/bridging/CallbackWrapper.h:34:41: note: 'createWeak' declared here

> Task :expo-modules-core:buildCMakeDebug[armeabi-v7a] FAILED

MethodMetadata.cpp中重复出现的错误:

/Users/abc/Documents/React_Native_Apps/app-new/node_modules/expo-modules-core/android/src/main/cpp/MethodMetadata.cpp:40:57: error: too many arguments to function call, expected 3, have 4
/Users/abc/.gradle/caches/transforms-3/05f8c5110695b559e432038ccd78233f/transformed/jetified-react-android-0.72.0-debug/prefab/modules/react_nativemodule_core/include/react/bridging/CallbackWrapper.h:34:41: note: 'createWeak' declared here

已尝试的操作

  • 删除node_modules并重新安装
  • 清理npm/yarn缓存
  • 执行./gradlew clean

环境版本

  • "expo": "^48.0.0"
  • "react-native": "~0.72.0"
  • Android Studio Flamingo | 2022.2.1 Patch 1(也试过Patch 2)
  • 设备:Macbook M2 Pro

解决方案

1. 版本适配(推荐)

Expo 48官方适配的React Native版本是0.71.x,当前使用的react-native: ~0.72.0属于跨版本不兼容,这是导致C++层API不匹配的核心原因。

  • 降级React Native到0.71.x:修改package.json中react-native版本为~0.71.14,执行:
    rm -rf node_modules && rm package-lock.json yarn.lock
    npm install
    ./gradlew clean
    
  • 或升级Expo到49:Expo 49适配React Native 0.72.x,将expo版本改为^49.0.0,同步升级相关依赖后重新安装。

2. 临时代码补丁(不推荐长期使用)

如果暂时无法调整版本,手动修改expo-modules-core的C++代码适配RN 0.72的API:

  • 修复JavaScriptModuleObject.cpp第238行:
    RN 0.72中LongLivedObjectCollection构造函数为私有,替换原std::make_shared代码为:
    auto collection = facebook::react::LongLivedObjectCollection::get();
    
  • 修复MethodMetadata.cpp第40行:
    查看CallbackWrapper.h中createWeak的定义,移除多余的第4个参数,匹配RN 0.72的API签名。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.17 22:32:09