今是昨非

今是昨非

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

Xcode14 compilation failure modification

Background#

After upgrading to Xcode 14, there were two compilation failures that needed to be addressed:

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

The first issue was relatively easy to solve, while the second one was a bit more complicated. The solutions are as follows:

Solutions#

Xcode 14 Bundle Code Sign Error#

To solve this issue, a Google search led to the first Stack Overflow link, Xcode 14 needs selected Development Team for Pod Bundles. The solution provided there was 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's team.

I have two projects, one primarily in Swift, and I tried the suggested method, which worked. It's important to note that if the project has multiple targets with different development teams, the settings need to be differentiated. You can refer to the commented code below for an example.

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 my other Objective-C project, this method didn't work, which was quite strange. So I found another solution from a CocoaPods issue, Xcode 14 build failed with manual code sign and app resource bundles. One of the solutions mentioned there was 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. I tried this code in both projects, and it successfully compiled.

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

This error indicates an incompatibility between Swift versions. Upon closer inspection, it became clear that the error was related to a third-party SDK used in my project, which was integrated using Carthage. It seemed that the issue was caused by the xcframeworks compiled with Carthage. So I attempted to recompile the xcframeworks, but the compilation of the Moya library kept failing. When I tried to compile Moya manually, it succeeded for the real device but failed for the simulator, with the error message Could not find module 'Alamofire' for target 'x86_64-apple-ios-simulator'. It was quite challenging to find a solution for this issue, but eventually, I found one in Using Carthage with Xcode 12. This method allows you to remove the arm64 simulator architecture from the compiled framework.

The solution is as follows:

remove arm64 simulator architecture from compiled framework

By the way, my computer does not have "Macs running Apple Silicon"; it has an Intel chip.

References#

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