如何在Xcode6中创建通用框架

5
我知道如何在Xcode 5中创建一个框架。但是在Xcode 6中,如何将模拟器框架和设备框架组合起来呢?当我尝试组合时,会出现代码签名错误。当我使用lipo来组合两个框架时,也会出现错误。 错误信息:Command /bin/sh failed with exit code 65

你正在创建静态库吗? - srinivas n
你的组合库(.a文件)意味着有调试版(debug.a)和发布版(release.a),请向我展示你的lipo语句。 - srinivas n
2个回答

15

我在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”文件夹并获取通用框架。


1
这对我非常有效。我唯一做出的更改是删除-arch x86_64。这导致无法在i386模拟器(5s之前的任何内容)上运行的问题。-sdk iphonesimulator为编译器提供了足够的信息,以便为i386和x86_64构建。如果您明确指定一个,则会排除另一个。谢谢! - Chad
2
@Chad 你是怎么移除 -arch x86_64 的?因为当我从运行脚本中移除它后,模拟器仍然无法运行。 - Ansari Awais
2
@Chad,模拟器上也无法运行。 - Tapas Pal
这只在设备上运行,而不在模拟器上运行,请问你能帮忙吗? - Kashif
@Kashif 请检查“Debug-universal”文件夹并获取通用框架。通用框架仅适用于设备和模拟器。 - Rajesh Loganathan
显示剩余5条评论

0

替换

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

清理构建


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接