iOS SDK开发,工程配置教程

1.创建一个用于管理demo project和sdk project的workspace.

xcode-File-New-Workspace -- MySDKDev.xcworkspace

2.创建sdk project, 选择framework project -- MySDK.xcodeproj

3.创建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/


# 创建输出目录,并删除之前的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了

你可能感兴趣的:(iOS SDK开发,工程配置教程)