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.

4
  • 2
    Did you solve this ? I am getting this now also
    – Lenny D
    Sep 18, 2018 at 13:06
  • possible duplicate: stackoverflow.com/questions/52385600/…
    – Marshall
    Sep 19, 2018 at 20:34
  • @Marshall I posted this question a while ago. Cheers
    – TheBen
    Sep 23, 2018 at 2: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. github.com/apache/cordova-ios/issues/407
    – TheBen
    Sep 23, 2018 at 2:13

5 Answers 5

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"

7
  • Thanks this worked for me - are there any known issues e.g. uploading to the App Store when this build flag is set? Sep 30, 2018 at 7:39
  • 2
    The reason is that Xcode 10 has a new build system that cordova-ios does not yet support. See this announcement. Oct 4, 2018 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, 2018 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, 2018 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, 2018 at 19:05
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.

5
  • 2
    Same for me, I litteraly tried everything for hours! This comment saved me! Jan 12, 2019 at 18:06
  • 1
    Same here. This should be the correct solution/answer
    – Lirianna
    Jan 15, 2019 at 12:54
  • 1
    This worked for me as well. For what it's worth, in my environment (cordova/ionic app) I noticed that the build still works even though it errors out.
    – Kinglish
    Jan 16, 2019 at 19:26
  • I prefer this answer
    – David
    Jan 27, 2019 at 19:35
  • Unplugging my device seems to work for me as well. However, when I run ionic cordova run -- --device I have to plug in my device again so I still get the error. I need to deploy the app through Xcode itself.
    – Ralph
    Apr 29, 2019 at 5:42
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.

2
  • 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 3, 2019 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 Apr 9, 2019 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

6
  • 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 3, 2019 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 :) Apr 4, 2019 at 9: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 Apr 4, 2019 at 9:41
  • ops sir my mistake archive not found in the location?
    – Kapil Soni
    Apr 4, 2019 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 Apr 9, 2019 at 12:33
0

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

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.