Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Failed to build module from its module interface; it may have been damaged or it may have triggered a bug in the Swift compiler when it was produced

When creating an xcframework like this

xcodebuild archive -project endiosOne-iOS.xcodeproj -scheme EOFoundation -destination="iOS" -archivePath /tmp/xcf/ios.xcarchive -derivedDataPath /tmp/iphoneos -sdk iphoneos SKIP_INSTALL=NO BUILD_LIBRARIES_FOR_DISTRIBUTION=YES

xcodebuild archive -project endiosOne-iOS.xcodeproj -scheme EOFoundation -destination="iOS Simulator" -archivePath /tmp/xcf/iossimulator.xcarchive -derivedDataPath /tmp/iphoneos -sdk iphonesimulator SKIP_INSTALL=NO BUILD_LIBRARIES_FOR_DISTRIBUTION=YES

xcodebuild -create-xcframework -framework /tmp/xcf/ios.xcarchive/Products/Library/Frameworks/EOFoundation.framework -framework /tmp/xcf/iossimulator.xcarchive/Products/Library/Frameworks/EOFoundation.framework -output /tmp/xcf/EOFoundation.xcframework

Then adding the framework to an existing project or a new project we get this error where we import the framework.

Failed to build module 'EOFoundation' from its module interface; it may have been damaged or it may have triggered a bug in the Swift compiler when it was produced

Using xcode 12.1, also tried with Xcode 11. Tried with new UIKit application and new SwiftUI only application

We get the following UIKit Errors UIKit Errors

I cant fix the UIkit errors as its in the UIKit: Unfortunately apple does not give us a lot of information on how to fix this.

How can I fix this so I use a xcframework that I have generated in another project?

like image 289
user1898829 Avatar asked Dec 07 '20 11:12

user1898829


2 Answers

I posted a feedback request to Apple for this issue and they suggested the following:

We can tell you that there is one known issue that fits your description: If your module is called “MyModuleName” and it also declares or imports a type called “MyModuleName”, names in the file that are supposed to refer to the module will be resolved to the type instead, causing errors when you try to import it. The Swift open source project’s bug tracker describes this bug and workarounds for it in a public article at https://bugs.swift.org/browse/SR-14195

Sure enough, the type I was exporting from my framework was named exactly as the module I was importing it from. Renaming the type resolved the problem for me.

like image 192
ikaz Avatar answered Oct 05 '22 23:10

ikaz


In my case, a precompiled XCFramework I was relying on was not recompiled when I changed the iOS deployment target. I recompiled the XCFramework and it fixed the issue.

like image 20
Genki Avatar answered Oct 06 '22 00:10

Genki