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

Detox构建产物输出至Release目录,RN测试因找不到二进制文件失败

问题

非Expo React Native项目集成Detox时,构建产物路径与配置不匹配:

  • 配置.detoxrc.json中binaryPath指定为./ios/build/Build/Products/Debug-iphonesimulator/<app-name>.app
  • 执行yarn detox build -c ios后,产物实际输出到./ios/build/Build/Products/Release-iphonesimulator/<app-name>.app
  • 运行测试时出现错误:
10:10:18.446 detox[5677] ERROR: Failed to find the app binary at:
/Users/<me>/Documents/buyer-app/ios/build/Build/Products/Debug-iphonesimulator/<app-name>.app

完整.detoxrc.json配置:

{
  "testRunner": "jest",
  "runnerConfig": "e2e/config.json",
  "skipLegacyWorkersInjection": true,
  "apps": {
    "ios": {
      "type": "ios.app",
      "binaryPath": "./ios/build/Build/Products/Debug-iphonesimulator/<app-name>.app",
      "build": "xcodebuild -workspace ios/<app-name>.xcworkspace -configuration debug -scheme '<app-name>' -sdk iphonesimulator -derivedDataPath ios/build"
    },
    "android": {
      "type": "android.apk",
      "binaryPath": "android/app/build/outputs/apk/feat/debug/app-debug.apk",
      "build": "cd android && ./gradlew assembleFeatDebug -x bundleFeatReleaseJsAndAssets -DtestBuildType=debug && cd .."
    }
  },
  "devices": {
    "simulator": {
      "type": "ios.simulator",
      "device": {
        "type": "iPhone 13 Pro"
      }
    },
    "emulator": {
      "type": "android.emulator",
      "device": {
        "avdName": "Pixel_3a_API_32_arm64-v8a"
      }
    }
  },
  "configurations": {
    "ios": {
      "device": "simulator",
      "app": "ios"
    },
    "android": {
      "device": "emulator",
      "app": "android"
    }
  }
}
解决方法
  1. 修正xcodebuild命令,强制指定构建输出目录
    修改.detoxrc.json中iOS的build命令,添加CONFIGURATION_BUILD_DIR参数明确指定Debug产物路径,同时将-configuration参数改为规范的首字母大写Debug:

    "build": "xcodebuild -workspace ios/<app-name>.xcworkspace -configuration Debug -scheme '<app-name>' -sdk iphonesimulator -derivedDataPath ios/build CONFIGURATION_BUILD_DIR=ios/build/Build/Products/Debug-iphonesimulator"
    
  2. 清理旧构建缓存
    执行以下命令删除旧构建产物,避免缓存干扰新构建:

    rm -rf ios/build
    
  3. 检查Xcode Scheme配置
    打开Xcode,进入Product > Scheme > Edit Scheme,确认Run和Build阶段的Configuration都设置为Debug,未被强制改为Release。

完成以上步骤后,重新执行yarn detox build -c ios,产物会输出到指定的Debug目录,测试即可正常运行。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.16 06:15:33