今是昨非

今是昨非

日出江花红胜火,春来江水绿如蓝

Xcode 14 Compilation Failure Fix

Background#

After upgrading to Xcode 14, modifications were made to fix compilation failures in the project. Two types of compilation errors were addressed:

  • One is the bundle code sign error, Xcode 14 needs selected Development Team for Pod Bundles
  • The other is Module compiled with Swift 5.6.1 cannot be imported by the Swift 5.7 compiler

The first type is relatively easy to solve, while the second type is a bit more troublesome. The solutions are as follows:

Solution#

Xcode 14 Bundle Code Sign Error#

For this issue, simply search on Google. The first link on Stack Overflow is Xcode 14 needs selected Development Team for Pod Bundles. The solution provided there is to add the following code to the Podfile, and then run Pod install to set the DEVELOPMENT_TEAM of the Pod library to the developer account's team.

I have two projects, one of which is primarily Swift. I tried the following method and it worked. Note that if the project has multiple targets with different developer teams, you need to differentiate the settings, as shown in the commented code below.

post_install do |installer|
  installer.generated_projects.each do |project|
    project.targets.each do |target|
        target.build_configurations.each do |config|
            config.build_settings["DEVELOPMENT_TEAM"] = "Your Team ID"
#            if target.name == 'test'
#            config.build_settings["DEVELOPMENT_TEAM"] = "Your Team ID"
#          else
#            config.build_settings["DEVELOPMENT_TEAM"] = "Your Another Team ID"
#          end
         end
    end
  end
end

However, in another OC project of mine, this method didn't work, which was quite strange. So I found another solution from an issue on CocoaPods, Xcode 14 build failed with manual code sign and app resource bundles . One of the solutions mentioned there is to set CODE_SIGN_IDENTIFY to an empty string, as shown below:

post_install do |installer|
  installer.pods_project.targets.each do |target|
      target.build_configurations.each do |config|
          config.build_settings['CODE_SIGN_IDENTITY'] = ''
      end
  end
end

This approach avoids the need to differentiate the DEVELOPMENT_TEAM settings. By setting the above code in both projects, successful compilation can be achieved.

Module compiled with Swift 5.6.1 cannot be imported by the Swift 5.7 compiler#

At first glance, this error indicates an incompatibility between Swift versions. Upon closer inspection, it should be noted that the library mentioned in the error is a third-party SDK. For my project, it is integrated using Carthage. Yes, it seems to be caused by the xcframeworks compiled with Carthage. So I went ahead and recompiled the xcframeworks. However, when compiling, the Moya library kept failing. When I tried to compile Moya manually, it succeeded on a real device but failed on the simulator, with the error Could not find module 'Alamofire' for target 'x86_64-apple-ios-simulator'. It was difficult to figure out, but after searching for a long time, I finally found a solution in Using Carthage with Xcode 12. This method can remove arm64 simulator architecture from compiled framework.

The solution is as follows:

remove arm64 simulator architecture from compiled framework

By the way, my computer is not a Macs running Apple Silicon, but rather an Intel-based one.

References#

Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.