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

从Windows 10切换到Ubuntu 22.04后运行旧React Native项目遇问题

解决React Native在Ubuntu 22.04上运行时librnscreens.so缺失的问题

错误根源

ERROR Error: Exception in HostObject::get for prop 'RNSModule':
java.lang.UnsatisfiedLinkError: dlopen failed: library "librnscreens.so" not found, js engine: hermes
ERROR Invariant Violation: Failed to call into JavaScript module method AppRegistry.runApplication(). Module has not been registered as callable. Registered callable JavaScript modules (n = 11): Systrace, JSTimers, HeapCapture, SamplingProfiler, RCTLog, RCTDeviceEventEmitter, RCTNativeAppEventEmitter, GlobalPerformanceLogger, JSDevSupportModule, HMRClient, RCTEventEmitter. A frequent cause of the error is that the application entry file path is incorrect. This can also happen when the JS bundle is corrupt or there is an early initialization error when loading React Native., js engine: hermes

核心问题是react-native-screens库的原生编译产物未被正确打包进APK,导致App启动时无法加载该库,进而引发后续JS初始化失败。

解决方案步骤

1. 清理项目缓存与冗余构建文件

  • 清理Android构建缓存:
    cd android && ./gradlew clean
    rm -rf .gradle build
    
  • 清理Node依赖与RN缓存:
    cd ..
    rm -rf node_modules package-lock.json yarn.lock
    npm install
    npx react-native start --reset-cache
    

2. 确保react-native-screens版本与RN兼容

  • 检查package.json中react-native-screens版本,确保与你的React Native版本匹配(例如RN 0.7x需对应react-native-screens@^3.20.0及以上)
  • 若版本不兼容,重装适配版本:
    npm uninstall react-native-screens
    npm install react-native-screens@<适配版本号>
    

3. 验证原生链接配置(RN 0.60+自动链接)

  • 检查android/settings.gradle是否包含以下内容:
    include ':react-native-screens'
    project(':react-native-screens').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-screens/android')
    
  • 检查android/app/build.gradle的dependencies块是否有:
    implementation project(':react-native-screens')
    
    (自动链接会自动添加,若缺失手动补上)

4. 重新构建并运行项目

  • 执行构建命令:
    npx react-native run-android
    
    或直接编译APK:
    cd android && ./gradlew assembleDebug
    

5. 额外排查点(若以上步骤无效)

  • 确认Ubuntu上的NDK版本符合RN要求(RN 0.7x推荐NDK 25.x)
  • 检查android/local.properties中是否配置了正确的NDK路径:
    ndk.dir=/path/to/ndk/25.2.9519653
    

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.25 06:53:43