IOS Framework 制作教程 for xcode7 (一)

来源:互联网 发布:汽车配件淘宝店铺名字 编辑:程序博客网 时间:2024/04/29 18:21
xcdod7 创建framework的步骤
1、创建一个静态库工程

2、删除工程目录中的.m文件
3、新建Headers并将创建的.h文件移到剪头所示的位置



4、更改头文件的内容
5、加入已经准备好需要打到framework中的文件 并将需要公开的头文件加入到headers的 public 下面

6、添加一个Run Script 更名为 Build FrameWork 并在脚本中加入如下内容

set -e

export FRAMEWORK_LOCN=
"${BUILT_PRODUCTS_DIR}/${PRODUCT_NAME}.framework"

# Create the path to the real Headers die
mkdir -p
"${FRAMEWORK_LOCN}/Versions/A/Headers"

# Create the required symlinks
/bin/ln -sfh A
"${FRAMEWORK_LOCN}/Versions/Current"
/bin/ln -sfh Versions/Current/Headers
"${FRAMEWORK_LOCN}/Headers"
/bin/ln -sfh
"Versions/Current/${PRODUCT_NAME}" \
"${FRAMEWORK_LOCN}/${PRODUCT_NAME}"

# Copy the public headers into the framework
/bin/cp -a
"${TARGET_BUILD_DIR}/${PUBLIC_HEADERS_FOLDER_PATH}/" \
"${FRAMEWORK_LOCN}/Versions/A/Headers"

7、更改framework 支持的架构和系统版本


8、配置Build Settings

选择Build Setting栏,然后搜索public header,双击Public Headers Folder Path,在弹出视图中键入如图所示内容:


使用搜索框,改变下述设置:
  • Dead Code Stripping设置为NO

  • Strip Debug Symbol During Copy 全部设置为NO

  • Strip Style设置为Non-Global Symbols

9、选择
运行编译 command+B

10、在现有工程中新建target 并选择Others中的 aggregate 并将其命名为Framework
11、选中target Framework 在其Target Dependencies中加入静态库文件
12、新增Run Script 命名为MultiPlatform Build 添加Framework 的多类型cpu的支持
在脚本文件中加入如下内容
set -e

# If we're already inside this script then die
if [ -n
"$RW_MULTIPLATFORM_BUILD_IN_PROGRESS" ]; then
exit
0
fi
export RW_MULTIPLATFORM_BUILD_IN_PROGRESS=
1

RW_FRAMEWORK_NAME=${PROJECT_NAME}
RW_INPUT_STATIC_LIB=
"lib${PROJECT_NAME}.a"
RW_FRAMEWORK_LOCATION=
"${BUILT_PRODUCTS_DIR}/${RW_FRAMEWORK_NAME}.framework"

function build_static_library {
   
# Will rebuild the static library as specified
   
#     build_static_library sdk
    xcrun xcodebuild -project
"${PROJECT_FILE_PATH}" \
    -target
"${TARGET_NAME}" \
    -configuration
"${CONFIGURATION}" \
    -sdk
"${1}" \
    ONLY_ACTIVE_ARCH=NO \
    BUILD_DIR=
"${BUILD_DIR}" \
    OBJROOT=
"${OBJROOT}" \
    BUILD_ROOT=
"${BUILD_ROOT}" \
    SYMROOT=
"${SYMROOT}" $ACTION
}

function make_fat_library {
   
# Will smash 2 static libs together
   
#     make_fat_library in1 in2 out
    xcrun lipo -create
"${1}""${2}" -output"${3}"
}

# 1 - Extract the platform (iphoneos/iphonesimulator) from the SDK name
if [[
"$SDK_NAME" =~ ([A-Za-z]+) ]]; then
RW_SDK_PLATFORM=${BASH_REMATCH[
1]}
else
echo
"Could not find platform name from SDK_NAME: $SDK_NAME"
exit
1
fi

# 2 - Extract the version from the SDK
if [[
"$SDK_NAME" =~ ([0-9]+.*$) ]]; then
RW_SDK_VERSION=${BASH_REMATCH[
1]}
else
echo
"Could not find sdk version from SDK_NAME: $SDK_NAME"
exit
1
fi

# 3 - Determine the other platform
if [
"$RW_SDK_PLATFORM" =="iphoneos" ]; then
RW_OTHER_PLATFORM=iphonesimulator
else
RW_OTHER_PLATFORM=iphoneos
fi

# 4 - Find the build directory
if [[
"$BUILT_PRODUCTS_DIR" =~ (.*)$RW_SDK_PLATFORM$ ]]; then
RW_OTHER_BUILT_PRODUCTS_DIR=
"${BASH_REMATCH[1]}${RW_OTHER_PLATFORM}"
else
echo
"Could not find other platform build directory."
exit
1
fi

# Build the other platform.
build_static_library
"${RW_OTHER_PLATFORM}${RW_SDK_VERSION}"

# If we're currently building for iphonesimulator, then need to rebuild
#   to ensure that we get both i386 and x86_64
if [
"$RW_SDK_PLATFORM" =="iphonesimulator" ]; then
build_static_library
"${SDK_NAME}"
fi

# Join the 2 static libs into 1 and push into the .framework
make_fat_library
"${BUILT_PRODUCTS_DIR}/${RW_INPUT_STATIC_LIB}" \
"${RW_OTHER_BUILT_PRODUCTS_DIR}/${RW_INPUT_STATIC_LIB}" \
"${RW_FRAMEWORK_LOCATION}/Versions/A/${RW_FRAMEWORK_NAME}"

# Ensure that the framework is present in both platform's build directories
cp -a
"${RW_FRAMEWORK_LOCATION}/Versions/A/${RW_FRAMEWORK_NAME}" \
"${RW_OTHER_BUILT_PRODUCTS_DIR}/${RW_FRAMEWORK_NAME}.framework/Versions/A/${RW_FRAMEWORK_NAME}"

# Copy the framework to the user's desktop
ditto"${RW_FRAMEWORK_LOCATION}""${HOME}/Desktop/${RW_FRAMEWORK_NAME}.framework"


13、修改target支持的架构类型
14、运行command+B 并查看生成的framework支持的架构类型  

0 0
原创粉丝点击