标签:iphone data 运行程序 eve 无法 color create hit 出现
首先声明一下,我是一个菜鸟,只是在工作中需要给别的公司提供SDK所以学习了如何去打包生成属于自己的SDK,有什么不足的地方,还希望大家能够指正.
好了,废话不多说,首先,我使用的Xcode版本是7.2,新建一个工程,在进入页面之后,选择Framework & Libray 选项中的 Cocoa Touch Framework.
因为要打包所需的文件,所以这里我自己创建了CveniEs.h,CveniEs.m文件,并且自定义了一个初始化方法,在,初始化方法中调用了 - (void)getString:(NSString *)string方法,并且打印了一句话,为了证明生成framework之后确实走了该方法;在实际工作过程中,直接把需要打包的所有文件拖到该工程中即可,
然后选中Target,选中Build Phases -> Headers,可以看出有三个选项,分别是Public,Private,Project;把需要暴露给别人的.h文件拖到Public中,剩下的不要暴露的,即为隐藏的文件,放在Project中,
完成上述步骤之后,在littleCveniEs.h文件中,把所有需要暴露的.h文件都用#import <littleCveniEs/PublicHeader.h>引入,记住一定要将所有的需要暴露的.h文件都写在给定位置,不然编译后生成的.framework在引用的时候会有警告;
新建一个Target,选择Other - >Aggregate,重命名,PS:图中的标记太过于丑陋,可以忽略, - -!
选中新建的Target,点击Build Pharas ,选中左上角的+,New Run Script Phase;
点开Run Script,添加如下的脚本;
选中Targets中的第一个Target,也就是littleCveniEs,点击Build Setting -> Mach-O Type,选择Static Library,到这里会有一个问题存在,就是无法在iPhone5c上使用.framework,这是我们需要在Build Setting -> Architectures ->Architectures中添加armv7s
我们已经完成了所有的工作,可以选择Command + B,不过编译之前,按照下图选择正确的Target,编译完成后会自动弹出已经创建完成的.framework;
到这里,我们已经完成了百分之九十九的步骤了,导入自己创建的.framework可以实现方法的调用,不过,如果你需要隐藏的文件中含有通过Category创建的类,当你运行程序的时候会发现出现崩溃的现象,如下图,我在创建自己的.framework的时候随便写了一个NSString的Category,并且在初始化方法中调用了Category中的方法,程序直接出现了Unrecognized selector sent to instance 0x10008c098的错误,这时我们需要在引用我们.framework的工程中设置 Build Pharse -> Other Linker Flags中加上 -all_load 就OK了,再次运行工程,可以完成所有的打印过程.
作者:CveniEs
链接:https://www.jianshu.com/p/305b716df620
脚本代码:
# Sets the target folders and the final framework product. # 如果工程名称和Framework的Target名称不一样的话,要自定义FMKNAME # 例如: FMK_NAME = "MyFramework" FMK_NAME=${PROJECT_NAME} # Install dir will be the final output to the framework. # The following line create it in the root folder of the current project. INSTALL_DIR=${SRCROOT}/Products/${FMK_NAME}.framework # Working dir will be deleted after the framework creation. WRK_DIR=build DEVICE_DIR=${WRK_DIR}/Release-iphoneos/${FMK_NAME}.framework SIMULATOR_DIR=${WRK_DIR}/Release-iphonesimulator/${FMK_NAME}.framework # -configuration ${CONFIGURATION} # Clean and Building both architectures. xcodebuild -configuration "Release" -target "${FMK_NAME}" -sdk iphoneos clean build xcodebuild -configuration "Release" -target "${FMK_NAME}" -sdk iphonesimulator clean build # Cleaning the oldest. if [ -d "${INSTALL_DIR}" ] then rm -rf "${INSTALL_DIR}" fi mkdir -p "${INSTALL_DIR}" cp -R "${DEVICE_DIR}/" "${INSTALL_DIR}/" # Uses the Lipo Tool to merge both binary files (i386 + armv6/armv7) into one Universal final product. lipo -create "${DEVICE_DIR}/${FMK_NAME}" "${SIMULATOR_DIR}/${FMK_NAME}" -output "${INSTALL_DIR}/${FMK_NAME}" rm -r "${WRK_DIR}" open "${INSTALL_DIR}"
添加版本号:
想要获得版本信息就要先设置info.plist文件,在build Settings中设置,当然是在你创建的aggregate中设置
这时的脚本代码为
# Sets the target folders and the final framework product. # 如果工程名称和Framework的Target名称不一样的话,要自定义FMKNAME # 例如: FMK_NAME = "MyFramework" FMK_NAME=${PROJECT_NAME} # Install dir will be the final output to the framework. # The following line create it in the root folder of the current project. #${SDK_NAME} #SDK_VERSION=$(echo ${SDK_NAME} | grep -o ‘.{3}$‘) #/${DYLIB_CURRENT_VERSION} #/${CURRENT_PROJECT_VERSION} #版本获取 echo "${PROJECT_DIR}/${INFOPLIST_FILE}" buildNumber=$(/usr/libexec/PlistBuddy -c "Print :CFBundleVersion" "${PROJECT_DIR}/${INFOPLIST_FILE}") buildNumber="$buildNumber" echo "buildNumber = $buildNumber" shortVersion=$(/usr/libexec/PlistBuddy -c "Print :CFBundleShortVersionString" "${PROJECT_DIR}/${INFOPLIST_FILE}") shortVersion="$shortVersion" echo "shortVersion = $shortVersion" #自增build版本 buildVersion=$(echo ${buildNumber} | grep -o -E ‘\d{1,3}$‘) buildVersion=$(($buildVersion + 1)) buildVersion=".$buildVersion" echo "buildVersion = $buildVersion" #设置build版本 newBuildNumber="$shortVersion$buildVersion" echo "newBuildNumber = $newBuildNumber" /usr/libexec/PlistBuddy -c "Set :CFBundleVersion $newBuildNumber" "${PROJECT_DIR}/${INFOPLIST_FILE}" INSTALL_DIR=${SRCROOT}/Products/${buildNumber}/${FMK_NAME}.framework # Working dir will be deleted after the framework creation. WORK_DIR=build DEVICE_DIR=${WORK_DIR}/Release-iphoneos/${FMK_NAME}.framework SIMULATOR_DIR=${WORK_DIR}/Release-iphonesimulator/${FMK_NAME}.framework # -configuration ${CONFIGURATION} "Release" # Clean and Building both architectures. xcodebuild -configuration "Release" -target "${FMK_NAME}" -sdk iphoneos clean build xcodebuild -configuration "Release" -target "${FMK_NAME}" -sdk iphonesimulator clean build # Cleaning the oldest. if [ -d "${INSTALL_DIR}" ] then rm -rf "${INSTALL_DIR}" fi mkdir -p "${INSTALL_DIR}" cp -R "${DEVICE_DIR}/" "${INSTALL_DIR}/" cp -R "${SIMULATOR_DIR}/" "${INSTALL_DIR}/" # Uses the Lipo Tool to merge both binary files (i386 + armv6/armv7) into one Universal final product. lipo -create "${DEVICE_DIR}/${FMK_NAME}" "${SIMULATOR_DIR}/${FMK_NAME}" -output "${INSTALL_DIR}/${FMK_NAME}" rm -r "${WORK_DIR}" rm -rf "${INSTALL_DIR}/_CodeSignature" rm -rf "${INSTALL_DIR}/Info.plist" open "${INSTALL_DIR}"
标签:iphone data 运行程序 eve 无法 color create hit 出现
原文地址:https://www.cnblogs.com/sunmair/p/9304596.html