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

React Native构建的Debug APK未同步最新变更,求解决方法

React Native Debug APK 不同步代码变更的排查与修复

操作中的核心问题

  1. 错误使用生产环境bundle命令:你执行的npx react-native bundle加了--dev false,生成的是生产环境bundle,但Debug构建流程默认会优先读取Metro的开发缓存,导致新代码无法生效。
  2. 冗余执行npx react-native link:RN 0.60+版本已支持自动链接,手动执行该命令可能引发依赖冲突或缓存异常。

修正后的构建步骤

  • 项目根目录下彻底清理缓存:
    # 重置Metro缓存
    npx react-native start --reset-cache
    # 清除npm缓存(用yarn则替换为yarn cache clean)
    npm cache clean --force
    
  • 进入android目录清理gradle缓存:
    cd android
    ./gradlew cleanBuildCache
    ./gradlew clean
    
  • 根目录生成Debug专用bundle(离线Debug包需要此步骤):
    npx react-native bundle --platform android --dev true --entry-file index.js --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest android/app/src/main/res
    
  • 重新构建Debug APK:
    cd android
    ./gradlew assembleDebug
    

额外排查项

  • 检查android/app/build.gradle,确保Debug构建没有硬编码旧bundle路径:
    移除这类可能强制指定旧资源的配置:
    // 需删除的错误配置示例
    project.ext.react = [
        jsBundleDirDebug: file("../../old_bundle_location"),
    ]
    
  • 彻底卸载设备上的旧APK(包括多用户残留):
    adb uninstall com.your.app.package
    
  • 确认代码变更已保存到目标文件,未被.gitignore或其他工具忽略。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.28 09:25:11