Apple released Xcode New Build System with Xcode 9 in the preview mode. It wasn’t activated by default at that time. With Xcode 10, new build system activated by default, by adopting the new build system you might have faced some of the issues in your existing iOS projects. Apple is fully aware of some of those issues and created the separate release notes for the new build system. They also mentioned some of the known issues with possible workarounds. You can read complete release note of the new build system here. We have covered the internal details of the new build system in our previous blog post In this post, we will cover the top five issues iOS developer might have faced and might not be covered in the release notes in details e.g new build system behaviour with third-party tools.
Xcode 10: New Build System
Just a recap on the new build system, from Xcode 10, the new build setting can be activated from Xcode Files-> Project/Workspace Settings and we can toggle between legacy and new build system.
Check the previous blog post on Xcode new build system for detailed information about the build system. If you are building an iOS project from the command line using the xcodebuild then we have to pass additional parameter -UseNewModernSystem=YES will also force the new build system. The new build system is called xcbuild . The binary of the Apple’s xcbuild is located at the path mentioned below.
The New Build system runs the targets and it’s build phases in parallel to speed up the overall Swift build. Once activated from Xcode, we will start to get benefits as well as issues related to the new build system in our iOS projects. We will cover some of the most common issues that imposed by Xcode New Build System and a potential workaround to solve this problem at the moment of time. We will categorise these issues as per areas impacted in the iOS apps.
There are several new issues started to appear regarding the info.plist files when an iOS project builds using New Build System. Here are some of the rules that you must know regarding New Build System and Info.plist files
- There shouldn’t be any plist file in the Copy Bundle Resources build phase of any target. The new build system won’t able to build an app otherwise. Also, it doesn’t work if files copied multiple times in the bundle.
- The new build system has different precedence of running Info.plist step in the clean and incremental builds. In the clean build, the info.plist step after processing assets, before linking storyboards while for incremental build it runs before signing.
- If the target has just Info.plist value and without any Xcode referenced folders then Xcode build system fails the build.
There are some issues introduced for the iOS projects using CocoaPods. Some of the common issues are
- Development Pods doesn’t update unless we perform a clean build. The embed pods frameworks build phase not reliably executed. There is an issue on Github about this here
- Archive of the app might fail or there might be flaky behaviour in the app as some Cocoapods related build phase script doesn’t run reliably.
In short, Cocoapods and New build system don’t work well together.
3] Run Script Phase
With the new build system, you might have faced an issue with Run Script phase started failing or giving flaky results. Don’t worry, there is a good reason for this.
In Xcode 10, run script build phase has improved a lot, however, we have to help build process by specifying some input files for the run script phase. If we specified Input Files to the run scripts phase which is important for the build system to make the decision if run scripts need to be run or not for the dependent target build. Xcode build system tried to run some tasks in parallel and if the input for the run script phase hasn’t been generated then build system get confused and fails. It’s always the good idea to provide the input files to the run scripts wherever applicable. When the number of input files grown up then Xcode 10, gives us the way to specify all the input files in the .xcfilelist format and we can add this file as File List input in the build phase. Xcode build system will always run this build phase when there are no input files, changed input files or missing output file. It’s very important to add those files to avoid running this phase for all the incremental builds when it’s not required.
4] Clean Build Folder Action
With the new build system, the clean operation of Xcode has been deprecated and Clean Build Folder action has been introduced. The newly introduced operation removes all the derived data of the iOS application causing the cleaner builds from scratch. It means if you are using Cocoapods. it will rebuild all the frameworks from scratch and cause the huge delay in building iOS project. If you are using Carthage with prebuilt frameworks then it won’t affect that much. If you have the habit of doing clan build, you need to be extra careful about this wait. You may also face slow Xcode indexing issues.
5] XCCONFIG Files
Most of you might be using .xcconfig files to keep the Xcode build settings at one place for the particular targets. There are some issues that conditional variable assignment in the xcconfig files might not work as expected, causing the build failures. In order to check your xcconfig files, Apple recommended running following command.
defaults write com.apple.dt.XCBuild EnableCompatibilityWarningsForXCBuildTransition -bool YES
If this command shows any warnings or errors, we need to fix that to get stable builds.
The new build system from Apple is designed to improve the performance, stability and reliability of the Swift build. It will catch the configuration errors early in the application development. It’s been activated by default in Xcode 10 so sooner or later we have to update our build process to adapt to the new build system. Surely, it will bring a lot of configuration enhancement in the app. Have a migrated to the new build system yet? What are your experiences? Have you come across any other issues that are not mentioned in this post?