Cordova build iOS error: archive not found at path 'path/to/myApp.xcarchive"

Cordova build iOS error: archive not found at path 'path/to/myApp.xcarchive"

我一直在努力让 Cordova 和 运行 在我的 iPhone 上工作。我按照以下命令操作,但在构建时看到以下错误:

cordova create myApp org.apache.cordova.myApp myApp
cd myApp
cordova platform add ios 
cordova build ios

我收到以下错误:

Building project: /Users/ben/Desktop/myTest/platforms/ios/myTest.xcworkspace
    Configuration: Debug
    Platform: device
User defaults from command line:
    IDEArchivePathOverride = /Users/ben/Desktop/myTest/platforms/ios/myTest.xcarchive

Build settings from command line:
    CONFIGURATION_BUILD_DIR = /Users/ben/Desktop/myTest/platforms/ios/build/device
    SHARED_PRECOMPS_DIR = /Users/ben/Desktop/myTest/platforms/ios/build/sharedpch

Build settings from configuration file '/Users/ben/Desktop/myTest/platforms/ios/cordova/build-debug.xcconfig':
    CLANG_ALLOW_NON_MODULAR_INCLUDES_IN_FRAMEWORK_MODULES = YES
    CODE_SIGN_ENTITLEMENTS = $(PROJECT_DIR)/$(PROJECT_NAME)/Entitlements-$(CONFIGURATION).plist
    CODE_SIGN_IDENTITY = iPhone Developer
    ENABLE_BITCODE = NO
    GCC_PREPROCESSOR_DEFINITIONS = DEBUG=1
    HEADER_SEARCH_PATHS = "$(TARGET_BUILD_DIR)/usr/local/lib/include" "$(OBJROOT)/UninstalledProducts/include" "$(OBJROOT)/UninstalledProducts/$(PLATFORM_NAME)/include" "$(BUILT_PRODUCTS_DIR)"
    OTHER_LDFLAGS = -ObjC
    SWIFT_OBJC_BRIDGING_HEADER = $(PROJECT_DIR)/$(PROJECT_NAME)/Bridging-Header.h

error: archive not found at path '/Users/ben/Desktop/myTest/platforms/ios/myTest.xcarchive'
** EXPORT FAILED **

(node:4984) UnhandledPromiseRejectionWarning: Error code 65 for command: xcodebuild with args: -exportArchive,-archivePath,myTest.xcarchive,-exportOptionsPlist,/Users/ben/Desktop/myTest/platforms/ios/exportOptions.plist,-exportPath,/Users/ben/Desktop/myTest/platforms/ios/build/device
(node:4984) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:4984) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

我试过删除和添加平台。另外,还要卸载东西。

我在 macOS High Sierra 和 Xcode 10。

here.

有一个解决方法

如果您在命令行上构建,您可以指定 --buildFlag="-UseModernBuildSystem=0":

# Cordova CLI
cordova run ios --buildFlag='-UseModernBuildSystem=0'
cordova build ios --buildFlag='-UseModernBuildSystem=0'

# Ionic CLI
ionic cordova run ios -- --buildFlag="-UseModernBuildSystem=0"
ionic cordova build ios -- --buildFlag="-UseModernBuildSystem=0"

如果您使用 build.json 配置文件构建,您可以在 iOS 发布或调试配置下添加以下内容:

"buildFlag": [
  "-UseModernBuildSystem=0"
]

如果您在 Xcode IDE 中打开项目,您需要将工作区设置中的构建系统更改为 "Legacy Build System"

两种解决方案 - --buildFlag="-UseModernBuildSystem=0" 或设置旧版构建系统都不适合我。

出于某种原因,如果我确定在 运行 cordova 构建命令之前从我的计算机上的 USB 拔下我的 iPad 或 iPhone,错误只会消失。

也许我的配置有些古怪,但我想我会分享以防它对其他人有帮助。

如果您不想一直在构建标志中设置它,请打开您的 MyApp.xcworkspace 并转到:

旁注:是的,您需要通过在 cordova 中添加 ios 平台来始终执行此操作。 (例如,您删除并再次添加了 ios 平台)

File > Workspace settings > Choose for Build System: Legacy Build System

Cordova iOS 从 5.0.0 开始支持新的构建系统(参见 release notes)。

因此请将您的 package.json 更新为 "cordova-ios": "5.0.0"(或更高版本)并致电 npm install

请注意,之后我必须清除所有内容(删除目录平台、插件、www)才能使其正常工作。

当您 运行 cordova ios build --prod 将设备连接到 mac 时,也会发生这种情况。拔掉插头再试一次。