1.創(chuàng)建一個用于管理demo project和sdk project的workspace.
xcode-File-New-Workspace -- MySDKDev.xcworkspace
2.創(chuàng)建sdk project, 選擇framework project -- MySDK.xcodeproj
3.創(chuàng)建demo project, 選擇普通app project -- MySDKDemo.xcodeproj
4.打開MySDKDev.xcworkspace, 把MySDK.xcodeproj和MySDKDemo.xcodeproj拉到MySDKDev.xcworkspace中.
5.點MySDKDemo工程,MySDKDemo taret-General-Linked Frameworks and Libraies-添加MySDK.framework
6.在MySDK中便斥,添加要添加的文件,把需要暴露的文件威始,在Build Phases-Headers中枢纠,移到public中
配置Universal target,編程出真機以及模擬器都可以用的framework
1.選擇MySDK工程黎棠,添加target晋渺,選擇Cross-platform -- Aggregate -- MySDK-Universal
2.選擇MySDK-Universal target,Build Phases -- Target Dependecies -- 添加MySDK.framework
3.添加Run Script脓斩,填入 '../scripts/build-universal-framework.sh'
4.到workspace目錄木西,添加scripts文件夾,添加build-universal-framework.sh文件
UNIVERSAL_OUTPUTFOLDER=../build/
# 創(chuàng)建輸出目錄随静,并刪除之前的framework文件 mkdir -p "${UNIVERSAL_OUTPUTFOLDER}" rm -rf "${UNIVERSAL_OUTPUTFOLDER}/${PROJECT_NAME}.framework"
# 分別編譯模擬器和真機的Framework
xcodebuild -target "${PROJECT_NAME}" ONLY_ACTIVE_ARCH=NO -configuration ${CONFIGURATION} -sdk iphoneos? BUILD_DIR="${BUILD_DIR}" BUILD_ROOT="${BUILD_ROOT}" clean build
xcodebuild -target "${PROJECT_NAME}" ONLY_ACTIVE_ARCH=NO -configuration ${CONFIGURATION} -sdk iphonesimulator BUILD_DIR="${BUILD_DIR}" BUILD_ROOT="${BUILD_ROOT}" clean build
# 拷貝framework到univer目錄
cp -R "${BUILD_DIR}/${CONFIGURATION}-iphoneos/${PROJECT_NAME}.framework" "${UNIVERSAL_OUTPUTFOLDER}/"
# 合并framework八千,輸出最終的framework到build目錄
lipo -create -output"${UNIVERSAL_OUTPUTFOLDER}/${PROJECT_NAME}.framework/${PROJECT_NAME}"
"${BUILD_DIR}/${CONFIGURATION}-iphonesimulator/${PROJECT_NAME}.framework/${PROJECT_NAME}"
"${BUILD_DIR}/${CONFIGURATION}-iphoneos/${PROJECT_NAME}.framework/${PROJECT_NAME}"
5.回到xcode,選擇MySDK-Universal燎猛,Commond+B恋捆,編譯工程,在workspace目錄中重绷,會生成build文件夾沸停,里
面的MySDK.framework就是支持真機以及模擬器的framework了