Detox:在 Info.plist 文件中未找到字段 CFBundleIdentifier。

6

我有一个 ReactNative 版本为 0.63.2 的项目。它可以在模拟器上运行,也可以在实际设备上运行。现在决定开始使用Detox。

运行示例测试时,我遇到了以下错误:

Error: field CFBundleIdentifier not found inside Info.plist of app binary at /Users/jesus/Documents/projects/appname/ios/build/Build/Products/Debug-iphonesimulator/Appname.app

在我的 Info.plist 文件中:
<key>CFBundleIdentifier</key>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>

我的.detoxrc.json文件:

{
  "testRunner": "jest",
  "runnerConfig": "e2e/config.json",
  "configurations": {
    "ios": {
      "type": "ios.simulator",
      "binaryPath": "ios/build/Build/Products/Debug-iphonesimulator/Appname.app",
      "build": "xcodebuild -project ios/Appname.xcodeproj -scheme Appname -configuration Debug -sdk iphonesimulator -derivedDataPath ios/build",
      "device": {
        "type": "iPhone 11"
      }
    },
    "android": {
      "type": "android.emulator",
      "binaryPath": "android/app/build/outputs/apk/debug/app-debug.apk",
      "build": "cd android && ./gradlew assembleDebug assembleAndroidTest -DtestBuildType=debug && cd ..",
      "device": {
        "avdName": "Pixel_API_28_AOSP"
      }
    }
  }
}

我检查了Xcode>常规设置中是否设置了Bundle标识符,同时在构建设置>打包下也有一个字段,其中app.appname已正确设置。
4个回答

2

这与 Detox 没有关系。

请检查你的 .app 包内部的 Info.plist 文件(而不是你源代码里的 Info.plist)。很可能你的包是损坏的。每个应用程序都需要一个有效的 Bundle Identifier。在 Xcode 的构建设置中,PRODUCT_BUNDLE_IDENTIFIER 可能没有正确地定义。


谢谢关注这个问题!我发现应用程序实际上位于另一个目录而不是我预期的目录中。 - Chrisissorry

1

我遇到了相同的问题。

我在构建时遇到了问题,并通过复制粘贴运行react-native run-ios命令时react native使用的命令解决了这些问题,其中包含-destination id="{MyprojectID}"。为此,我删除了- derivedDataPath iOS / build,然后再次添加了它,以及-sdk iphonesimulator,我的构建命令如下:

xcodebuild -workspace iOS/{AppName}.xcworkspace -configuration Debug -scheme {AppName} -sdk iphonesimulator -derivedDataPath ios/build -destination id={MyprojectID}

0

我遇到了同样的问题,问题在于我试图测试错误的 .app 文件。你不能仅测试使用正确配置生成的 .app 文件。你不能使用使用adhoc证书或npx react-native run-ios创建的 .app 文件或从Xcode构建的文件。你必须使用detox build命令生成 .app 文件,并且必须提供该 .app 文件的路径。此外,调试配置的 .app 文件不适用于发布配置,反之亦然。


0
确保你首先构建应用程序,然后再运行测试。
detox build -c ios.sim.debug

这将构建捆绑包并在类似路径的位置创建一个二进制文件:
"/Users/<YourName>/Library/Developer/Xcode/DerivedData/<AppName-xxxxxxxxxxxxxxxxxxxxxxxxxxxx>/Build/Products/Debug-iphonesimulator/<AppName>.app"

如果你之前使用过其他模拟器,请确保删除DerivedData文件夹的内容,这样你就可以找到正确二进制文件的路径。
然后在detoxrc.js中更新此路径,在binaryPath下,这样你应该能够成功构建。
apps: {
  'ios.debug': {
    binaryPath: "/Users/<YourName>/Library/Developer/Xcode/DerivedData/<AppName-xxxxxxxxxxxxxxxxxxxxxxxxxxxx>/Build/Products/Debug-iphonesimulator/<AppName>.app",
    build: "xcodebuild -workspace ios/<AppName>.xcworkspace -configuration debug -scheme <AppName> -sdk iphonesimulator -derivedDataPath -destination id=35B6BBB5-489F-738B-W846-3B577458462K",
    type: 'ios.app',
  },
  // Other configurations
}

你终于可以运行测试了。
detox test -c ios.sim.debug

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接