xcode7.0 中制作动态Framework

一)新建工程并选择默认Target为Cocoa Touch Framework,如图所示:

 

二)随便添加一个测试用例:

mytest.h头文件中,包含#import "frameworktest.h"

三)设置开放的头文件:Framework中有些类可能是一些私有的辅助工具,不需要使用者看到,在这里只需要把开放出去的类放到Public下, 如图

 

四)到此为止,点击运行,就可以生成相应的framework的库,不过一般情况下分为模拟器和真机的库文件,所以需要用户自己去整合

使用命令:

lipo -info  xxxx.framework // 可以查看支持哪些编译器

lipo -create .framework/xxx .framework/xxx -output xxx  //将模拟器和真机生产的库整合为一个

就可以将多个framework合并为一个framework,其实被合并的是framework中的“.a”文件。

如果被打入framework中的文件是C++文件,即.mm文件,可能会报“___gxx_personality_sj0”错误

五)这里就直接讲另外一种直接讲两种库文件合并为一个的方法

 

 

然后,在Myappregate 添加sh脚本

# 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 clean build
xcodebuild -configuration "Release" -target "${FMK_NAME}" -sdk iphonesimulator clean build
# Cleaning the oldest.
if [ -d "${INSTALL_DIR}" ]
then
rm -rf "${INSTALL_DIR}"
fi
mkdir -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 "${INSTALL_DIR}"

 紧接着,需要修改一下Architectures,默认是没有armv7s参数的,最好两个都添加一下,不添加运行iphone 5c会出现问题

接着点击运行,如果没有问题的话,就会弹出生成的framework库,然后拷贝到自己新建的工程中去

六)新建测试工程

这里需要自己去添加用户添加的库头文件路径,如何回报找不到头文件的问题

当出现下面错误,需要用户自己去添加:

dyld: Library not loaded: @rpath/mytest.framework/mytest
  Referenced from: /Users/issuser/Library/Developer/CoreSimulator/Devices/59249D08-16DC-4B99-B93F-CC28BF18EBB7/data/Containers/Bundle/Application/E9DB65F3-9ABB-49DA-8E7F-82BF27396D6A/test123.app/test123
  Reason: image not found
(lldb)

 

 

 

posted @ 2015-10-21 15:47  【se7en】  阅读(222)  评论(0)    收藏  举报