Xcode 10.2 Cannot build Swift framework for ObjC app

(Quang) #1

I use the same build script I always use to build a Swift universal binary framework, but now my Objective-C app cannot read that binary framework headers anymore (even if I build with Swift 4.2 or 5). Is this a Xcode 10.2 bug?


# make sure the output directory exists
env > env.txt
# Step 1. Build Device and Simulator versions
xcodebuild -project "${PROJECT_NAME}.xcodeproj"  -target "${PROJECT_NAME}" ONLY_ACTIVE_ARCH=NO -configuration ${CONFIGURATION} -sdk iphoneos  BUILD_DIR="${BUILD_DIR}" BUILD_ROOT="${BUILD_ROOT}" clean build 
xcodebuild -project "${PROJECT_NAME}.xcodeproj" -target "${PROJECT_NAME}" -configuration ${CONFIGURATION} -sdk iphonesimulator ONLY_ACTIVE_ARCH=NO BUILD_DIR="${BUILD_DIR}" BUILD_ROOT="${BUILD_ROOT}" clean build

# Step 2. Copy the framework structure (from iphoneos build) to the universal folder

# Step 3. Copy Swift modules from iphonesimulator build (if it exists) to the copied framework directory
if [ -d "${SIMULATOR_SWIFT_MODULES_DIR}" ]; then

# Step 4. Create universal binary file using lipo and place the combined executable in the copied framework directory
lipo -create -output "${UNIVERSAL_OUTPUTFOLDER}/${PROJECT_NAME}.framework/${PROJECT_NAME}" "${BUILD_DIR}/${CONFIGURATION}-iphonesimulator/${PROJECT_NAME}.framework/${PROJECT_NAME}" "${BUILD_DIR}/${CONFIGURATION}-iphoneos/${PROJECT_NAME}.framework/${PROJECT_NAME}"

# Step 5. Convenience step to copy the framework to the project's directory

# Step 6. Convenience step to open the project's directory in Finder
open "${PROJECT_DIR}"
(Erik Little) #2

Are you using Carthage or something similar? I believe there was a change in the header that the Swift compiler generates that some dependency managers need to update to account for.

edit: Looks like you're using lipo, I've had users of one of my frameworks complain about this too

For reference: https://github.com/Carthage/Carthage/pull/2723

(Quang) #3

I tried the integration via Carthage/CocoaPods/manual, all doesn't work

(Quang) #4

I upgraded to Carthage 0.32 and tried carthage build also, the problem remains

(Quinn “The Eskimo!”) #5

I’m not sure what’s going on in this specific case, but i want to be clear that trying to build a framework that supports both device and simulator builds is not supported. That’s because iOS and the iOS Simulator are different platforms. For more background on this, see this DevForums thread.

Share and Enjoy

Quinn “The Eskimo!” @ DTS @ Apple

(Quang) #6

I built independently for 2 platforms, but I still don't know how to follow your post here as my framework requires being added to "Embedded Framework"
Edit: also ship both binary frameworks will make it impossible to deliver via CocoaPods or Carthage

(Quinn “The Eskimo!”) #7

I still don't know how to follow your post here as my framework
requires being added to "Embedded Framework"

I’m sad to say that all the advice I have on that topic is encapsulated in that DevForums post.

also ship both binary frameworks

A binary framework containing Swift? That’s a bad idea in general, due to Swift’s current lack of module stability (a restriction that’s being actively worked on).

Share and Enjoy

Quinn “The Eskimo!” @ DTS @ Apple

(Quang) #8

So Xcode team has put it in Known issues of Build System
It is due to merging header problem. I applied the fix suggested, things worked fine now

<contents of original iOS Simulator/Framework.framework/Framework-Swift.h>
<contents of original iOS/Framework.framework/Framework-Swift.h>


(Daniel) #9

@quangDecember could you please provide the script for the fix?

(Quang) #10

Please use the script below:

(Menny Alterscu) #11

hi i have the same issue
i have framework app write in swift
i have in the targets: tool (the framework) , and framework builder
i use xcode 10.2.1
i replace my script with yours (see attachment)
and i have example project with file in swift and file objc
the swift work fine
the objective c recognise the object from frame work but not the classes , function, and properties

please help

(Khoa Le) #12

Did you try setting Always Embed Swift Standard Libraries to true?

(Menny Alterscu) #13

In the framework project?

(Menny Alterscu) #14

the swift work , the objective c cant acsses to the class

(Quang) #15

I don't think "Always embed" is needed with Swift 5

(Quang) #16

did you check the modulename-Swift header file and see if the function is there yet?
it works fine on my side

(Menny Alterscu) #17

the script dont do it ?

(Menny Alterscu) #18

work fine xcode 10.1 without swift 4.2