ios 制作framework

原文:http://db-in.com/blog/2011/07/universal-framework-iphone-ios-2-0/

 

原文废话太多啊,自己总结一下,因为我是在原有的静态库工程基础上建立的,所以新建一个target就好了。

1 新建target,macOS中的bundle:

2 接下来设置bundle的build setting:(直接复制了)

  • Base SDK: Latest iOS (iOS X.X) (in the X.X will appear the number of the lastest iOS SDK installed on your machine).
  • Architectures: $(ARCHS_STANDARD_32_BIT) armv6 (it’s very important to be exactly this value including the space before “armv6″) This setting is valid to Xcode 4.2, if you are using an old version, use the “Standard (armv6 armv7)” option. (the values for this property depend on the value of the item bellow, so set that first).
  • Build Active Architecture Only: NO (otherwise we can’t compile to armv6 and armv7 at the same time).
  • Valid Architecture: $(ARCHS_STANDARD_32_BIT) (it’s very important to be exactly this value). If your Xcode is showing two lines with armv6 and armv7, delete then and insert this value in one single line.
  • Dead Code Stripping: NO.
  • Link With Standard Libraries: NO.
  • Mach-O Type: Relocatable Object File. This is the most important change. Here, we instruct the compiler to treat the Bundle as a relocatable file, by doing this, we can turn it into a framework with the wrapper setting.
  • Other Linker Flags: This setting is not mandatory, but if you are planning to use any kind of C++ code (.cpp or .mm) on this framework, Chris Moore (on the comments) advises to use the “-lstdc++” option. In this case could be a good idea to use “-ObjC” too, to avoid conflicts in old compilers.
  • Wrapper Extension: framework. Here we change the Bundle to a Framework. To Xcode, frameworks is just a folder with the extension .framework, which has inside one or more compiled binary sources, resources and some folders, a folder, usually called Headers, contains all the public headers.
  • Generate Debug Symbols: NO (this is a very important setting, otherwise the framework will not work on other computers/profiles).
  • Precompile Prefix Header: NO.
  • Prefix Header: “”. (Leave it blank).

IMPORTANT: Since the Xcode 4.x the architectures armv6 has no longer support. So, to create a real Universal Framework we must make a small “hack”:

  1. After change the settings above close the Xcode, find the .xcodeproj (the project file) in Finder and then “Show Package Contents”.
  2. Open the file “project.pbxproj” into a text editor.
  3. Delete all the lines with VALID_ARCHS = “$(ARCHS_STANDARD_32_BIT)”.

 

3 接下来在build phase 中添加各种资源,包括 Copy Bundle Resources,Compile Sources。要注意的是添加 Copy Headers,是区分开放和私有的。

  • Public: Headers that other developers must know in order to work with your framework. In the final framework product, these headers will be visible even to Xcode.
  • Private: Headers that is not necessary to other developers, but is good for consult or for reference. These headers will not be visible to Xcode, but will be in the framework folder.
  • Project: Headers that the other developers nor Xcode have access. In reality these headers will not be placed in the final product, this is just to instruct the compiler to create your custom framework. 

Tip: To add many files at once, click on the “+” button and write the files’ extension on the search field. For example “.m”, “.c”, “.cpp”, “.h”, etc. This can save a lot of time. (搜索后缀,可以节省不少时间。。)

4 接下来建立target,用来生成通用的framework。

在aggregate的build phases中添加run script:

# Sets the target folders and the final framework product.
FMK_NAME=FI
FMK_VERSION=A# 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# Building both architectures.
xcodebuild -configuration "Release" -target "${FMK_NAME}" -sdk iphoneos
xcodebuild -configuration "Release" -target "${FMK_NAME}" -sdk iphonesimulator# Cleaning the oldest.
if [ -d "${INSTALL_DIR}" ]
then
rm -rf "${INSTALL_DIR}"
fi# Creates and renews the final product folder.
mkdir -p "${INSTALL_DIR}"
mkdir -p "${INSTALL_DIR}/Versions"
mkdir -p "${INSTALL_DIR}/Versions/${FMK_VERSION}"
mkdir -p "${INSTALL_DIR}/Versions/${FMK_VERSION}/Resources"
mkdir -p "${INSTALL_DIR}/Versions/${FMK_VERSION}/Headers"# Creates the internal links.
# It MUST uses relative path, otherwise will not work when the folder is copied/moved.
ln -s "${FMK_VERSION}" "${INSTALL_DIR}/Versions/Current"
ln -s "Versions/Current/Headers" "${INSTALL_DIR}/Headers"
ln -s "Versions/Current/Resources" "${INSTALL_DIR}/Resources"
ln -s "Versions/Current/${FMK_NAME}" "${INSTALL_DIR}/${FMK_NAME}"# Copies the headers and resources files to the final product folder.
cp -R "${DEVICE_DIR}/Headers/" "${INSTALL_DIR}/Versions/${FMK_VERSION}/Headers/"
cp -R "${DEVICE_DIR}/" "${INSTALL_DIR}/Versions/${FMK_VERSION}/Resources/"# Removes the binary and header from the resources folder.
rm -r "${INSTALL_DIR}/Versions/${FMK_VERSION}/Resources/Headers" "${INSTALL_DIR}/Versions/${FMK_VERSION}/Resources/${FMK_NAME}"# 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}/Versions/${FMK_VERSION}/${FMK_NAME}"rm -r "${WRK_DIR}"

最后,build这个aggregate的target就可以了!!!

#################################

遇到的问题:

新建的bundle找不到Apple LLVM compiler的选项了,简直就是我累个擦啊!最后在原文的评论中发现了:先编译一遍,那些选项就回出现了。。。设置好了,重新build就可以了。。

转载于:https://www.cnblogs.com/hbf369/p/3217119.html

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/408612.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

一文了解下 GANs可以做到的事情

原文链接:https://machinelearningmastery.com/impressive-applications-of-generative-adversarial-networks/ 简介 如果说目前深度学习最火,应用最多的领域,莫过于 GAN–Generative Adversarial Network,翻译过来就是生成对抗…

浅析php学习的路线图

一直都想走上码农的道路,奈何当年没有学好。一直与码农无缘。现在又想做一些码农就下了一套某个培训机构的php视频来看。希望能走上码农的道路1.php初级教程 初级教程主要的页面设置的,就是 htmljsdivcss 2.中级教程中级的话开始接触php,就是php核心编程…

被垃圾分类逼疯?试试这款垃圾自动分类器

这是小编转载的第 31 篇好文来自:视说AI作者:视说君让垃圾自动分类近期垃圾分类成为了一个热门话题,原来直接一次性扔掉的垃圾,现在都需要分门别类进行投放。从今年7月1日起,新的《上海市生活垃圾管理条例》正式开始施…

Python基础入门6_文件和异常

Python 基础入门前五篇: Python 基础入门–简介和环境配置Python基础入门_2基础语法和变量类型Python基础入门_3条件语句和迭代循环Python基础入门_4函数Python基础入门_5面向对象基础 这次将介绍有关文件和异常的处理,包括读写文本文件、二进制文件、…

必读的10篇关于GAN的论文

前言 上次写的文章-- 一文了解下 GANs可以做到的事情,如果想进一步了解 GAN,学习研究 GAN,可以先从这 10 篇论文开始。 本文翻译自: https://towardsdatascience.com/must-read-papers-on-gans-b665bbae3317 原文介绍 10 篇介…

ArcGIS Server for JavaScript 3.3 的安装部署

一、安装包下载 首先从官网下载ArcGIS API for JavaScript 3.3 的API 和SDK,地址:http://support.esrichina.com.cn/2011/0223/960.html,需要注意的是,想获取API和SDK,需要注册一个Esri全球账户。 点击Library和SDK下载…

实战|手把手教你训练一个基于Keras的多标签图像分类器

图片来自 pexels,作者:Jean-Christophe Andr2019 年第 63 篇文章,总第 87 篇文章原文链接:https://www.pyimagesearch.com/2018/05/07/multi-label-classification-with-keras/作者:Adrian Rosebrock今天介绍的是基于 …

poj 2182 Lost Cows 解题报告

题意&#xff1a;每个奶牛都有一个编号&#xff0c;1- N 从第二个牛开始给出前面比她编号小的牛的个数&#xff0c;问你求牛的编号序列 解题思路:线段树 二分查找 (多个相同的数二分边界问题需要注意)  解题代码&#xff1a; 1 #include <stdlib.h>2 #include <stri…

基于Keras的多标签图像分类

原文链接&#xff1a;https://www.pyimagesearch.com/2018/05/07/multi-label-classification-with-keras/ 作者&#xff1a;Adrian Rosebrock 今天介绍的是基于 Keras 实现多标签图像分类&#xff0c;主要分为四个部分&#xff1a; 介绍采用的多标签数据集简单介绍使用的网…

快速入门 Jupyter notebook

2019 年第 64 篇文章&#xff0c;总第 88 篇文章本文大约 6400 字&#xff0c;阅读大约需要 17 分钟原文链接&#xff1a;https://www.dataquest.io/blog/jupyter-notebook-tutorial/Jupyter notebook 是一个很强大的交互式和展示数据科学项目的工具&#xff0c;它可以作为一个…

简单ORACLE分区表、分区索引

一段听说CSDN.COM里面很多好东西&#xff0c;同事建议看看合适自己也可以写一写&#xff0c;呵呵&#xff0c;今天第一次开通博客&#xff0c;随便写点东西&#xff0c;就以第一印象分区表简单写第一个吧。 ORACLE对于分区表方式其实就是将表分段存储&#xff0c;一般普通表格是…