这是我使用Swift语言的第一个框架,它是私有框架。在新的Xcode 9.3发布之前,它的工作正常。升级后更新Xcode
会遇到类似Module compiled with Swift 4.0.3 cannot be imported in Swift 4.1
的问题。
之后只有我意识到框架不支持自动版本(Xcode / Swift)升级,有些搜索发现有一个Universal or Fat Binary Framework
单个版本而不是我之前错过的真实设备和模拟器的单独构建
UNIVERSAL_OUTPUTFOLDER=${BUILD_DIR}/${CONFIGURATION}-universal
# Make sure the output directory exists
mkdir -p "${UNIVERSAL_OUTPUTFOLDER}"
# Next, work out if we're in SIM or DEVICE
xcodebuild -target "${PROJECT_NAME}" -configuration ${CONFIGURATION} -sdk iphonesimulator ONLY_ACTIVE_ARCH=NO BUILD_DIR="${BUILD_DIR}" BUILD_ROOT="${BUILD_ROOT}" clean build
xcodebuild -target "${PROJECT_NAME}" ONLY_ACTIVE_ARCH=NO -configuration ${CONFIGURATION} -sdk iphoneos BUILD_DIR="${BUILD_DIR}" BUILD_ROOT="${BUILD_ROOT}" clean build
# Step 2. Copy the framework structure (from iphoneos build) to the universal folder
cp -R "${BUILD_DIR}/${CONFIGURATION}-iphoneos/${PROJECT_NAME}.framework" "${UNIVERSAL_OUTPUTFOLDER}/"
# Step 3. Copy Swift modules from iphonesimulator build (if it exists) to the copied framework directory
BUILD_PRODUCTS="${SYMROOT}/../../../../Products"
cp -R "${BUILD_PRODUCTS}/Debug-iphonesimulator/${PROJECT_NAME}.framework/Modules/${PROJECT_NAME}.swiftmodule/." "${UNIVERSAL_OUTPUTFOLDER}/${PROJECT_NAME}.framework/Modules/${PROJECT_NAME}.swiftmodule"
# Step 4. Create universal binary file using lipo and place the combined executable in the copied framework directory
lipo -create -output "${UNIVERSAL_OUTPUTFOLDER}/${PROJECT_NAME}.framework/${PROJECT_NAME}" "${BUILD_PRODUCTS}/Debug-iphonesimulator/${PROJECT_NAME}.framework/${PROJECT_NAME}" "${BUILD_DIR}/${CONFIGURATION}-iphoneos/${PROJECT_NAME}.framework/${PROJECT_NAME}"
# Step 5. Convenience step to copy the framework to the project's directory
cp -R "${UNIVERSAL_OUTPUTFOLDER}/${PROJECT_NAME}.framework" "${PROJECT_DIR}"
# Step 6. Convenience step to open the project's directory in Finder
open "${PROJECT_DIR}"
fi
Edit Scheme
- > Archive
- > Post-Action
- > Run Script
这次我使用Swift Compiler - Language
- > Swift 3.3
我这次也在Xcode 9.3
Swift 4.1
当我尝试在Xcode 9.2
使用此框架运行项目时,它会显示如下错误
Module compiled with Swift 4.1 cannot be imported in Swift 3.2.3:
尝试以向后兼容性解决,但我没有找到。如何在Xcode 9.2
框架支持:Swift
和Objective C
,最低操作系统iOS 8.0
也有类似这样的错误
compiled with newer version of Swift language (unknown ABI version 0x06) than previous files (4.0) file 'MAC location' for architecture armv7
并尝试了this to my project