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

Android APK新版本构建更新未生效及相关异常问题求助

React Native Expo Android构建异常紧急修复方案

核心问题

  • 生产环境APK误用预发布(staging)凭据,导致Google登录报redirect_uri_mismatch
  • 应用内显示版本为1.8.0(读取自app.config.js),但系统应用信息显示1.8.4
  • 已执行删除android目录、npx expo prebuild(生产凭据)、校验google-services.json等操作,问题未解决

紧急排查修复步骤

1. 彻底清理缓存与残留

  • 执行 npx expo start --clear 清除Expo本地缓存
  • 删除项目根目录下的.expo文件夹,移除旧配置缓存
  • 清理Android Studio缓存:File → Invalidate Caches...,勾选"Clear file system cache and local history"后重启
  • 进入android目录执行 ./gradlew clean 清除Gradle构建残留

2. 强制环境配置隔离

  • 检查app.config.js是否通过环境变量区分生产/预发布配置,示例:
    export default ({ config }) => {
      const isProduction = process.env.NODE_ENV === 'production';
      return {
        ...config,
        version: isProduction ? '1.8.4' : '1.8.0',
        extra: {
          googleClientId: isProduction ? '生产环境ClientID' : '预发布ClientID',
          // 其他凭据配置
        }
      };
    };
    
  • 构建生产APK时明确传入环境变量:NODE_ENV=production npx expo prebuild --platform android

3. 验证Google服务配置生效

  • 确认android/app目录下的google-services.json为生产环境版本,未被预发布文件覆盖
  • 检查android/build.gradle和android/app/build.gradle,确保Google服务插件配置无硬编码的预发布参数

4. 修复版本号不一致问题

  • 确认app.config.js中version字段在生产环境下设置为1.8.4,而非仅修改versionCode
  • 检查android/app/build.gradle中的versionName是否同步为1.8.4(Expo prebuild会自动同步,但需确认无手动修改)
  • 应用内读取版本时,使用Constants.expoConfig.version替代本地缓存值,避免旧版本信息残留

5. 规范构建流程

  • 构建前删除所有旧APK文件,避免混淆
  • 若使用EAS Build,执行 npx expo build:android --profile production 明确指定生产环境构建
  • 安装新APK前彻底卸载旧版本应用,避免增量更新导致的配置残留

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.07 04:45:28