IOS静态库封装(四)

来源:互联网 发布:thinking in java在线 编辑:程序博客网 时间:2024/06/04 17:41

六、整合模拟器版本和真机版本。

添加Target:aggregate







       增加依赖项:







       增加脚本文件:



       更改脚本命和脚本内容:

 

       脚本命:MultiPlatform Build

       脚本内容:

set -e# If we're already inside this script then dieif [ -n "$RW_MULTIPLATFORM_BUILD_IN_PROGRESS" ]; thenexit 0fiexport RW_MULTIPLATFORM_BUILD_IN_PROGRESS=1RW_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 nameif [[ "$SDK_NAME" =~ ([A-Za-z]+) ]]; thenRW_SDK_PLATFORM=${BASH_REMATCH[1]}elseecho "Could not find platform name from SDK_NAME: $SDK_NAME"exit 1fi# 2 - Extract the version from the SDKif [[ "$SDK_NAME" =~ ([0-9]+.*$) ]]; thenRW_SDK_VERSION=${BASH_REMATCH[1]}elseecho "Could not find sdk version from SDK_NAME: $SDK_NAME"exit 1fi# 3 - Determine the other platformif [ "$RW_SDK_PLATFORM" == "iphoneos" ]; thenRW_OTHER_PLATFORM=iphonesimulatorelseRW_OTHER_PLATFORM=iphoneosfi# 4 - Find the build directoryif [[ "$BUILT_PRODUCTS_DIR" =~ (.*)$RW_SDK_PLATFORM$ ]]; thenRW_OTHER_BUILT_PRODUCTS_DIR="${BASH_REMATCH[1]}${RW_OTHER_PLATFORM}"elseecho "Could not find other platform build directory."exit 1fi# 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_64if [ "$RW_SDK_PLATFORM" == "iphonesimulator" ]; thenbuild_static_library "${SDK_NAME}"fi# Join the 2 static libs into 1 and push into the .frameworkmake_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 directoriescp -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 desktopditto "${RW_FRAMEWORK_LOCATION}" "${HOME}/Desktop/${RW_FRAMEWORK_NAME}.framework"

选中我们的TargetFramework,再次编译CMD+B,会发现桌面上已经出现我们需要得静态库文件:MyFirstStaticLib.framework



将此文件放入任意工程即可使用。




博主脸皮甚厚,若有说错或者描述不清的地方,请回复留言,多多指教!


转载请注明出处:http://blog.csdn.net/dengbin9009/article/details/36178067

0 0
原创粉丝点击