标签:
一、创建原生态文件
1.创建库文件的最原始文件(Cocoa Touch Static Library 类型的静态库工程 RWUIControls)
2.删除掉无用文件.m,保留.h
3.在Build Phases中添加所用到的framework文件
4.Editor\Add Build Phase\Add Copy Headers Build Phase。将保留的.h文件和用户要调用的接口文件放入到Header中的public中。
(public:公共头文件 外部调用时即从这里来获取方法定义【用】)
(private:私有的,但是也会暴露在外面)
(project:不被用户看到的【用】)
尽可能少的类成为public,并确保其他非public的头文件都在Project下。
二、做配置
1.更改公共头文件存放位置
Build Setting - > Packaging - > Public Headers Folder Path
2.删除掉无用代码
3.Dead Code Stripping 设置为NO
4.Strip Debug Symbol During Copy 全部设置为NO
5.Strip Style 设置为Non-Global Symbols
6.目标选择为iOS Device ,command + B ,Products目录下出现黑色的.a文件。
三、关闭到静态项目,新建一个app项目。
四、对app项目进行静态库文件测试、调试。
1.将静态库项目中的.xcodeproj文件拖动到app项目中。
2.点击app项目名,在phases中添加拖进来的静态库项目中的.a文件
3.将文件名包含到最初创建的那个.h文件中。#import “fkdsl.h”
五、添加脚本在phases中。
1.脚本在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"
iOS Device构建目标,然后使用cmd+B构建
2.在.a文件上右击,选择Show in Finder
此时,包含了.framework文件。但没有lib文件。
六、添加lib文件
arm7: 在最老的支持iOS7的设备上使用
arm7s:在iPhone5和5C上使用
arm64:运行于iPhone5S的64位ARM处理器上
i386:32位模拟器上使用
x86_64:64为模拟器上使用
1.Editor/ Add Targets/
2.iOS/Other/Aggregate 点击Next,将目标命名为Framework。
3.往静态库目标中添加依赖(Dependency),即点击Framework,Build Phases下Target Dependencies(1 item)下的“+”号,添加之前生成好的RWUIControls静态库
4.添加Script Build Phase.
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"
5.选择Framework后Command + B
此时在桌面生成了Framework.
标签:
原文地址:http://blog.csdn.net/kangli_1990/article/details/51336176