此文章是https://stackoverflow.com/questions/25248598/importing-commoncrypto-in-a-swift-framework翻译而来。
- 首先你需要创建一个Aggregate target
- 如下图设置runScript
runScript代码如下:# This if-statement means we'll only run the main script if the CommonCryptoModuleMap directory doesn't exist # Because otherwise the rest of the script causes a full recompile for anything where CommonCrypto is a dependency # Do a "Clean Build Folder" to remove this directory and trigger the rest of the script to run if [ -d "${BUILT_PRODUCTS_DIR}/CommonCryptoModuleMap" ]; then echo "${BUILT_PRODUCTS_DIR}/CommonCryptoModuleMap directory already exists, so skipping the rest of the script." exit 0 fi mkdir -p "${BUILT_PRODUCTS_DIR}/CommonCryptoModuleMap" cat <<EOF > "${BUILT_PRODUCTS_DIR}/CommonCryptoModuleMap/module.modulemap" module CommonCrypto [system] { header "${SDKROOT}/usr/include/CommonCrypto/CommonCrypto.h" export * } EOF
- framework添加target
- 添加支持的平台
- 设置引用路径
此处切记要加上:$(inherited) ${BUILT_PRODUCTS_DIR}/CommonCryptoModuleMap
之后就可以在对应的文件 import CommonCrypto ,编译一下可以编译通过的。
-
Xcode 10现在附带了一个CommonCrypto模块映射,因此不需要进行这种变通。如果您想同时支持Xcode 9和10,您可以在运行脚本阶段检查模块映射是否存在,例如:
COMMON_CRYPTO_DIR="${SDKROOT}/usr/include/CommonCrypto" if [ -f "${COMMON_CRYPTO_DIR}/module.modulemap" ] then echo "CommonCrypto already exists, skipping" else # generate the module map, using the original code above fi