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

旧版本React Native项目构建失败:依赖解析错误求助

解决React Native旧版本构建时的依赖冲突问题

错误核心原因

你的项目使用React Native 0.64.2,但react-native-vibration包依赖要求RN版本为0.12.+,版本范围不兼容,导致Gradle无法解析依赖。

解决方案

方案1:改用RN内置的振动模块(推荐)

React Native 0.64.x的振动功能是内置在核心库中的,无需安装第三方react-native-vibration包:

  • 卸载第三方包:
    npm uninstall react-native-vibration
    # 或用yarn
    yarn remove react-native-vibration
    
  • 修改代码中的导入语句:
    将
    import Vibration from 'react-native-vibration';
    
    替换为
    import { Vibration } from 'react-native';
    

方案2:强制Gradle使用当前RN版本

在android/build.gradle中添加依赖强制策略,让react-native-vibration适配当前RN版本:

  1. 打开项目根目录下的android/build.gradle
  2. 在allprojects块中添加resolutionStrategy:
    allprojects {
        repositories {
            // 保留原有仓库配置
        }
        configurations.all {
            resolutionStrategy {
                force 'com.facebook.react:react-native:0.64.2'
            }
        }
    }
    
  3. 清理Gradle缓存并重新构建:
    cd android
    gradlew.bat clean # Windows系统
    # macOS/Linux用 ./gradlew clean
    npm run android
    

方案3:安装适配RN 0.64.x的react-native-vibration版本

查找并安装与RN 0.64.x兼容的react-native-vibration版本:

npm install react-native-vibration@^6.0.0
# 该版本适配RN 0.60+,可根据实际情况调整

额外注意事项

  • 旧版RN的很多功能模块后来从核心分离为独立包,不同版本的独立包对RN核心版本要求严格,务必匹配对应版本
  • 若构建仍有问题,可清理项目缓存后重试:
    rm -rf node_modules && npm install
    cd android && gradlew.bat clean
    

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.20 00:54:57