我知道如何在Xcode 5中创建一个框架。但是在Xcode 6中,如何将模拟器框架和设备框架组合起来呢?当我尝试组合时,会出现代码签名错误。当我使用
lipo
来组合两个框架时,也会出现错误。
错误信息:Command /bin/sh failed with exit code 65
lipo
来组合两个框架时,也会出现错误。
错误信息:Command /bin/sh failed with exit code 65
我在xcode6中创建通用框架的解决方案。
尝试以下步骤:
步骤1:
File—>
New —>
Project —>
Framework & Library —>
Next —>
Product Name
步骤2:创建自定义类文件
步骤3:
Target ->
Build phase ->
Headers,
将所有头文件设为公共文件。现在可以在模拟器和设备中构建。
步骤4:File ->
New ->
Target ->
iOS ->
Other ->
Aggrigate ->somename eg: framework
步骤5:
From Targets —>
Custom aggregate target(Eg: Framework)—>
Build Phase—>
Add Run script
步骤6:在运行脚本中添加以下Shell代码
///
UNIVERSAL_OUTPUTFOLDER=${BUILD_DIR}/${CONFIGURATION}-universal
# make sure the output directory exists
mkdir -p "${UNIVERSAL_OUTPUTFOLDER}"
# Step 1. Build Device and Simulator versions
xcodebuild -target "${PROJECT_NAME}" ONLY_ACTIVE_ARCH=NO -configuration ${CONFIGURATION} -sdk iphoneos BUILD_DIR="${BUILD_DIR}" BUILD_ROOT="${BUILD_ROOT}" clean build
xcodebuild -target "${PROJECT_NAME}" -configuration ${CONFIGURATION} -sdk iphonesimulator -arch x86_64 BUILD_DIR="${BUILD_DIR}" BUILD_ROOT="${BUILD_ROOT}" clean build
# Step 2. Copy the framework structure to the universal folder
cp -R "${BUILD_DIR}/${CONFIGURATION}-iphoneos/${PROJECT_NAME}.framework" "${UNIVERSAL_OUTPUTFOLDER}/"
# Step 3. 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_DIR}/${CONFIGURATION}-iphonesimulator/${PROJECT_NAME}.framework/${PROJECT_NAME}" "${BUILD_DIR}/${CONFIGURATION}-iphoneos/${PROJECT_NAME}.framework/${PROJECT_NAME}"
步骤7:
Goto active scheme —>
Custom aggregate —>
Build
第8步:现在在Xcode的产品中,右键单击framework并选择“在Finder中显示”。
检查“Debug-universal”文件夹并获取通用框架。
替换
xcodebuild -target "${PROJECT_NAME}" -configuration ${CONFIGURATION} -sdk iphonesimulator -arch x86_64 BUILD_DIR="${BUILD_DIR}" BUILD_ROOT="${BUILD_ROOT}" clean build
使用
xcodebuild -target "${PROJECT_NAME}" -configuration ${CONFIGURATION} -sdk iphonesimulator ONLY_ACTIVE_ARCH=NO BUILD_DIR="${BUILD_DIR}" BUILD_ROOT="${BUILD_ROOT}" clean build
清理构建