Uploaded image for project: 'Apache Cordova'
  1. Apache Cordova
  2. CB-8254

Swift support: Cordova build only uses xcconfig with --device flag (please also enable without)

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 3.5.0, 4.1.3
    • Fix Version/s: 3.8.0
    • Component/s: cordova-cli, cordova-ios
    • Labels:
    • Environment:

      All (iOS)

      Description

      I have written a plugin in Swift that won't build with a deployment target < iOS 7.0. This breaks "cordova build ios":

      Swift is unavailable on iOS earlier than 7.0; please set IPHONEOS_DEPLOYMENT_TARGET to 7.0 or later (currently it is '6.0').
      (** BUILD FAILED **)

      I know I can `cordova prepare ios` and manually add the changes to my xcode project, but as a plugin author this manual approach is unsatisfactory. Instead, I have added a hook to my plugin that adds the required options to build.xcconfig:

      "IPHONEOS_DEPLOYMENT_TARGET = 7.0"
      "SWIFT_OBJC_BRIDGING_HEADER = $SRCDIR/Bridging-Header.h"

      This allows the code to build with `cordova build ios --device`

      The problem is that `cordova build ios` alone doesn't pay any attention to the any of the three build.xcconfig files, because there is no -xcconfig option present for EMULATOR mode in the build script (see $PROJECT/platforms/ios/cordova/build).

      -------

      The solution:

      The ideal solution would be the option to provide custom build options to `cordova prepare ios` that get directly integrated into the Xcode project. But I gather Apple doesn't provide us the option to edit Xcode projects outside of Xcode (and 3rd party solutions are far from reliable).

      Which appears to leave us with two reasonable options:

      (1) Provide another Xcode project for Swift plugins. Back maybe this isn't so reasonable after all: it's inconsistent, has the issue of setting a Bridging Header without knowing where it is in advance. What happens when we add a swift plugin to an existing project. Does the existing Xcode project get deleted?

      (2) Add the same -xcconfig param to the EMULATOR section at the bottom of the `ios/cordova/build` file. This has the drawback of potentially confusing people when they open the Xcode project, but I think this is favourable to having the project not build at all from the command line.

      Is there any reason that (2) couldn't be implemented effectively immediately?

        Issue Links

          Activity

          Hide
          shazron Shazron Abdullah added a comment -

          Option 2 - sounds reasonable to me

          Show
          shazron Shazron Abdullah added a comment - Option 2 - sounds reasonable to me
          Hide
          matt.ridley Matthew Ridley added a comment -

          I agree, option 2 sounds like the best option. I see this becoming a bigger issue as Swift gains more popularity. (I found this post because I was having the same issues)

          Show
          matt.ridley Matthew Ridley added a comment - I agree, option 2 sounds like the best option. I see this becoming a bigger issue as Swift gains more popularity. (I found this post because I was having the same issues)
          Hide
          jira-bot ASF subversion and git services added a comment -

          Commit 875d699dc2c03c065082677ea8ee8d80efec4cc6 in cordova-ios's branch refs/heads/master from Shazron Abdullah
          [ https://git-wip-us.apache.org/repos/asf?p=cordova-ios.git;h=875d699 ]

          CB-8254 - Enable use of .xcconfig when building for emulator

          Show
          jira-bot ASF subversion and git services added a comment - Commit 875d699dc2c03c065082677ea8ee8d80efec4cc6 in cordova-ios's branch refs/heads/master from Shazron Abdullah [ https://git-wip-us.apache.org/repos/asf?p=cordova-ios.git;h=875d699 ] CB-8254 - Enable use of .xcconfig when building for emulator
          Hide
          geojay Geordie Jay added a comment - - edited

          Thank you Shazron!
          See https://gist.github.com/ephemer/b65d379d5a96237d186d for the plugin hook I'm using to make this work with Swift

          Show
          geojay Geordie Jay added a comment - - edited Thank you Shazron! See https://gist.github.com/ephemer/b65d379d5a96237d186d for the plugin hook I'm using to make this work with Swift

            People

            • Assignee:
              shazron Shazron Abdullah
              Reporter:
              geojay Geordie Jay
            • Votes:
              1 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Time Tracking

                Estimated:
                Original Estimate - 2h
                2h
                Remaining:
                Remaining Estimate - 2h
                2h
                Logged:
                Time Spent - Not Specified
                Not Specified

                  Development