56

I have been struggling to get Cordova to work and run on my iPhone. I follow the commands below but see error below at build:

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

I get the error below:

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.

I have tried removing and adding platforms. Also, uninstalling stuff as well.

I'm on macOS High Sierra and Xcode 10.

Shashank Agrawal
  • 25,161
  • 11
  • 89
  • 121
TheBen
  • 3,410
  • 3
  • 26
  • 51
  • 2
    Did you solve this ? I am getting this now also – Lenny D Sep 18 '18 at 13:06
  • possible duplicate: https://stackoverflow.com/questions/52385600/ionic-ios-build-fails-error-archive-not-found/52388081 – Marshall Sep 19 '18 at 20:34
  • @Marshall I posted this question a while ago. Cheers – TheBen Sep 23 '18 at 02:12
  • 1
    @LennyD, I have gone back to an older version of Cordova but it seems like the team has got to it and there are some work around it. I havn't had a chance to try out the workaround yet. Cheer. https://github.com/apache/cordova-ios/issues/407 – TheBen Sep 23 '18 at 02:13

5 Answers5

143

There is a work around here.

If you're building on the command-line, you can specify --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"

If you're building with a build.json config file, you can add the following under the iOS release or debug config:

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

If you are opening the project in the Xcode IDE, you need to change the build system in Workspace Settings to "Legacy Build System"

Samuel Hsieh
  • 1,546
  • 1
  • 7
  • 5
  • Thanks this worked for me - are there any known issues e.g. uploading to the App Store when this build flag is set? – Adam Diament Sep 30 '18 at 07:39
  • 2
    The _reason_ is that Xcode 10 has a new build system that `cordova-ios` does not yet support. See this [announcement](https://github.com/apache/cordova-ios/issues/407). – Alex Steinberg Oct 04 '18 at 15:10
  • 2
    In XCode 10 - to change to Legacy Build System use File->Project Settings-Build System->Legacy Build System. The "--buildflag" workaround worked initially for me then didn't. Also Cordova Clean kept throwing errors/failing. Once I switched to the Legacy Build all was fine. – kiwi209 Oct 10 '18 at 18:46
  • 1
    No longer working for me (XCode 10, Ionic v4 beta 11). Try this: I followed the comment advice above. Open XCode, go to File -> Workplace Settings -> Build System… select Legacy Build System. Then, back in your CLI, run: ionic cordova run ios -l – dotNetkow Oct 14 '18 at 16:58
  • I have followed the advice and still get the error: CordovaError: Promise rejected with non-error: 'Error code 65 for command: xcodebuild with args: -exportArchive,-archivePath.... However, it seems to still build the .xcodeproj file correctly – Kinglish Nov 30 '18 at 19:05
  • Excellent answer. 100th vote up. Congratulation for you Great Question badge – w3spi Feb 17 '19 at 12:10
  • it not working for me sir...@kiwi209 i have got same as urs error, do you have fix this error? – Kapil Soni Apr 03 '19 at 10:46
47

Neither solution - --buildFlag="-UseModernBuildSystem=0" or setting the Legacy Build System worked for me.

For some reason, the error only goes away if I am sure to unplug my iPad or iPhone from usb on my computer before running the cordova build command.

Maybe something quirky about my configuration, but I thought I'd share in case it helps anyone else.

jessica
  • 3,051
  • 2
  • 30
  • 31
4

Cordova iOS supports the new build system since 5.0.0 (see release notes).

So update your package.json to "cordova-ios": "5.0.0" (or later) and call npm install.

Note, that I had to clean out everything (delete the directories platforms, plugins, www) afterwards in order for it to work.

nharrer
  • 618
  • 7
  • 21
  • sir i have tried above solution but i got above error : Error: xcodebuild: Command failed with exit code 65 in the CLI? – Kapil Soni Apr 03 '19 at 12:15
  • @Kapilsoni that's a code signing issue actually, open yourapp.xcworkspace like I mentioned in the comments above and then run your build again and ofc set the legacy build system – Stefan Rein Apr 09 '19 at 12:57
3

If you don't want to set it in the build flag all the time, open your MyApp.xcworkspace and go to:

Sidenote: Yes you need to do this all the time by adding the ios platform in cordova. (e.g. you removed and added again the ios platform)

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

enter image description here

Stefan Rein
  • 8,084
  • 3
  • 37
  • 37
  • not working for me sir got below error : error: archive not found at path '/Users/kapil/Desktop/project/AMS/platforms/ios/AMS.xcarchive' ** EXPORT FAILED ** ? – Kapil Soni Apr 03 '19 at 10:37
  • @Kapilsoni If this archive present there or not? If not, add the ios platform with ionic / cordova, then it should be there :) – Stefan Rein Apr 04 '19 at 09:17
  • @Kapilsoni You still did not answer, is this archive existent or not: /Users/kapil/Desktop/project/AMS/platforms/ios/AMS.xcarchive There should also be another xcworkspace which you should open. If not, remove and add the platform again or try otherwise to create this file. Maybe there is also another error which caused this – Stefan Rein Apr 04 '19 at 09:41
  • ops sir my mistake archive not found in the location? – Kapil Soni Apr 04 '19 at 10:02
  • @Kapilsoni just go to the path and open the `/Users/yourusername/PROJECTS/app/platforms/ios/yourapp.xcworkspace` and set the signing and the legacy build system and run again, then it should work. Had this yesterday – Stefan Rein Apr 09 '19 at 12:33
  • finally sir its worked for me i have jump above location and set legacy build system and run.finally error is resolved.thank you sir – Kapil Soni Apr 10 '19 at 05:58
0

This also happens when you run cordova ios build --prod with a device connected to your mac. Unplug and try again.

Jelmer Jellema
  • 1,072
  • 10
  • 16