* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

New Build System (Preview) first appeared in Xcode 9. Compared to the Legacy Build System, the New Build System provides significantly faster Build times, stricter code quality checks (cyclic references, etc.), and friendlier hints. But in Xcode 9, New Build System is not the default and is not widely used. After upgrading to Xcode 10, New Build System replaces Legacy Build System as the default (see File -> Project Settings, figure 1).

The project maintained by the author has the ability to package the Framework. The package script works normally before the upgrade to Xcode 10 (Figure 2), but after the upgrade, the package script is disabled (Figure 3).

The package script is as follows:

# merge QiShareSDK compiled on real and emulator
If the project name is not the same as the Framework Target name, use a custom FMKNAME
FMK_NAME="QiShareSDK"
# INSTALL_DIR is the framework export path
Create a framework folder at the root of the project.
INSTALL_DIR=${SRCROOT}/QiShareFrameworks/${FMK_NAME}.framework
WRK_DIR will be removed after the framework is synthesized
WRK_DIR=build
DEVICE_DIR=${WRK_DIR}/Release-iphoneos/${FMK_NAME}.framework
SIMULATOR_DIR=${WRK_DIR}/Release-iphonesimulator/${FMK_NAME}.framework
# Clean The framework for both architectures
xcodebuild OTHER_CFLAGS="-fembed-bitcode" -configuration "Release" -target "${FMK_NAME}" -sdk iphoneos clean build
xcodebuild OTHER_CFLAGS="-fembed-bitcode" -configuration "Release" -target "${FMK_NAME}" -sdk iphonesimulator clean build
Delete the previously generated framework
if [ -d "${INSTALL_DIR}" ]
then
rm -rf "${INSTALL_DIR}"
fi
mkdir -p "${INSTALL_DIR}"
cp -R "${DEVICE_DIR}/" "${INSTALL_DIR}/"
# synthetic
lipo -create "${DEVICE_DIR}/${FMK_NAME}" "${SIMULATOR_DIR}/${FMK_NAME}" -output "${INSTALL_DIR}/${FMK_NAME}"
# remove WRK_DIR
rm -r "${WRK_DIR}"
# open INSTALL_DIR
open "${INSTALL_DIR}"
Copy the code

Normal framework compiled (with content in framework) :

Compiled error framework (no content in framework) :

Based on experience, I guess the new compilation system is the cause. Sure enough, after changing the Build System in File -> Project Settings from New Build System to Legacy Build System, the problem is resolved.

However, this would result in the entire project being unable to use the New Build System, which is not what the authors wanted, and presumably not what the developers and Apple wanted. Therefore, it would be a good solution to specify separately that the framework packaging process does not use the New Build System.

Through searching and experimenting, we can use -usemodernBuildSystem =NO to specify that the XCodeBuild command does not use the current build system. Therefore, the authors make adjustments to the xcodebuild command line of the packaging script as follows:

xcodebuild OTHER_CFLAGS="-fembed-bitcode" -configuration "Release" -target "${FMK_NAME}" -sdk iphoneos clean build -UseModernBuildSystem=NO
xcodebuild OTHER_CFLAGS="-fembed-bitcode" -configuration "Release" -target "${FMK_NAME}" -sdk iphonesimulator clean build -UseModernBuildSystem=NO
Copy the code

Then, run the script under The New Build System and find that it can be packaged normally, and the problem is resolved.

PS: QiShare summarized some of the issues after the new system upgrade, but also some that were not. Welcome to comment and discuss. After upgrading Mojave, Xcode10 cannot run the program after starting the emulator. What should I do? Can’t get WiFi SSID in iOS 12? Don’t panic!


QiShare(Simple book) QiShare(digging gold) QiShare(Zhihu) QiShare(GitHub) QiShare(CocoaChina) QiShare(StackOverflow) QiShare(wechat public account)


Writing High Quality Objective-C code for iOS (6) Qiwu Weekly 278