Demo地址:https://github.com/ma762614600/iOS_Framework
第一步:制作framework
原文链接:打包自己的framework(Xcode7&OSX10.11)兼容各种cpu类型

第一步:新建Framework项目

第二步:编写代码,构建完成项目

第三步:新建一个我们用来运行编译脚本的Target

第四步:在新建的Target里边添加一个脚本

第五步:填入脚本

第六步:运行并根据需要编译
# Sets the target folders and the final framework product.# 如果工程名称和Framework的Target名称不一样的话,要自定义FMKNAME# 例如: FMK_NAME = "MyFramework"FMK_NAME=${PROJECT_NAME}# Install dir will be the final output to the framework.# The following line create it in the root folder of the current project.INSTALL_DIR=${SRCROOT}/Products/${FMK_NAME}.framework# Working dir will be deleted after the framework creation.WRK_DIR=build
DEVICE_DIR=${WRK_DIR}/Release-iphoneos/${FMK_NAME}.framework
SIMULATOR_DIR=${WRK_DIR}/Release-iphonesimulator/${FMK_NAME}.framework# -configuration ${CONFIGURATION}# Clean and Building both architectures.xcodebuild -configuration "Release" -target "${FMK_NAME}" -sdk iphoneos -arch armv7 -arch armv7s -arch arm64 clean build
xcodebuild -configuration "Release" -target "${FMK_NAME}" -sdk iphonesimulator -arch x86_64 clean build# Cleaning the oldest.if [ -d "${INSTALL_DIR}" ]thenrm -rf "${INSTALL_DIR}"fimkdir -p "${INSTALL_DIR}"cp -R "${DEVICE_DIR}/" "${INSTALL_DIR}/"# Uses the Lipo Tool to merge both binary files (i386 + armv6/armv7) into one Universal final product.lipo -create "${DEVICE_DIR}/${FMK_NAME}" "${SIMULATOR_DIR}/${FMK_NAME}" -output "${INSTALL_DIR}/${FMK_NAME}"rm -r "${WRK_DIR}"open "${SRCROOT}/Products/"
检测类库支持的版本(注意指向framework内部)
lipo -info ~/Documents/SFMapKit/Products/SFMapKit.framework/SFMapKit
第二步:解决会遇到的问题:
原文链接:XCode6添加自定义framework运行真机出现dyld: Library not loaded的解决方法
1、直接添加上面制作好的framework,会发报如下错误:
dyld: Library not loaded: @rpath/RLLibrary.framework/RLLibrary
Referenced from: /var/mobile/Applications/AE92B234-A818-445E-9D69-96E232BD50EB/RLProjectDemo.app/RLProjectDemo
Reason: image not found
(lldb)
讨论:看网上不少人说是将上图Link Binary With Libraries中的Required改为Optional就没事了,实际真机运行发现不是回事,即使不报错了,但是也是无法运行程序。
解决方法:仔细看错误原因,应该是没有找到framework文件包,So,怎么编译时打包进去呢?如下图,点击那个+号:
添加Copy Files节点,在Destination中选Frameworks,再点击下面+号,选择自定义的framework,ok,真机 Build,Run,这个世界美好了。

2、即使上面都已经配置好了,程序运行ok,但是当引用库中.h文件时,会警告“missing submodule 'XXXframework'”
解决方法:创建库文件时,只要在库文件中与库同名.h文件中添加要暴露的.h文件,有点绕,可以看下图:

注:稍后我会把我自己的demo传到github,再把整个流程细细梳理一遍,分享给大家!
-------------------------------------------------2015年11月27日编辑如下:--------------------------------------------------
Demo地址:https://github.com/ma762614600/iOS_Framework
来源:oschina
链接:https://my.oschina.net/u/1265766/blog/617705