如何归档包含自定义框架的应用程序? [英] How to archive an app that includes a custom framework?

查看:211
本文介绍了如何归档包含自定义框架的应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个我创建的xcode框架项目,我可以编译成 myframework.framework 文件。编译之后,我将此框架拖到我的应用程序的Frameworks项目文件夹中,然后使用框架中的类,我将适当的 import 语句添加到任何需要的类中它;这允许我的应用程序成功编译,并引用框架中定义的类。为了使应用程序部署成功到我的设备,我还将我的自定义框架添加到我的目标的嵌入式二进制文件部分。完成所有这些后,我可以从xcode构建我的应用程序并在我的设备上运行它。



当我尝试存档应用程序商店的应用程序时出现问题。当我尝试这样做时,我得到了大量的编译器错误,其中xcode表示无法找到我的自定义框架中定义的任何类的声明。



怎么能我在xcode中设置了存档,以便正确引用和嵌入我的自定义框架?

解决方案

你实际上不需要放它在嵌入式​​二进制文件部分。您只需要在链接的框架和库部分中。确保您的框架是一个通用框架(意味着它可以编译所有体系结构),并确保您设置了正确的编译器标志(-ObjC,如果您的框架有任何框架)类别等)如果您的框架包含任何c代码并且您想在客户端应用程序中启用bitcode,那么您可能需要设置其他一些内容,例如其他C标志,那么您应该在其中添加-fembed-bitcode框架其他C标志。这些是我需要做的事情才能将我的框架应用程序带到商店。我认为这只是一个误解,你需要将它放在嵌入式二进制文件中,以便将它存档到商店。 / p>

这是我用来生成通用框架的构建脚本。它构建在我的桌面上。如果您的框架在Swift中,您可以取消注释第8节。您想要创建聚合目标并在构建阶段将其添加为运行脚本。

  #Merg e脚本

#1
#设置bash脚本在任何命令失败时立即退出。
set -e

#2
#设置一些常量以供日后使用。
FRAMEWORK_NAME =MyFramework

#3
#如果存在先前版本的残余,请删除它们。
if [-d$ {SRCROOT} / build];那么
rm -rf$ {SRCROOT} / build
fi

#4
#构建设备和模拟器的框架(使用
#所有需要的架构)。
xcodebuild -target$ {FRAMEWORK_NAME} - 配置发布-arch arm64 -arch armv7 -arch armv7s only_active_arch = no defines_module = yes -sdkiphoneos
xcodebuild -target$ {FRAMEWORK_NAME} - 配置发布-arch x86_64 -arch i386 only_active_arch = no defines_module = yes -sdkiphonesimulator

#5
#删除.framework文件,如果在上次运行的桌面上存在。
if [-d$ {HOME} / Desktop / $ {FRAMEWORK_NAME} .framework];然后
rm -rf$ {HOME} / Desktop / $ {FRAMEWORK_NAME} .framework
fi

#6
#将框架的设备版本复制到桌面。
cp -r$ {SRCROOT} / build / Release-iphoneos / $ {FRAMEWORK_NAME} .framework$ {HOME} / Desktop / $ {FRAMEWORK_NAME} .framework

# 7
#用
#替换框架内的框架可执行文件#通过将设备和模拟器
#frameworks'可执行文件与lipo合并而创建的新版本。
lipo -create -output$ {HOME} /桌面/ $ {FRAMEWORK_NAME} .framework / $ {FRAMEWORK_NAME}$ {SRCROOT} / build / Release-iphoneos / $ {FRAMEWORK_NAME} .framework / $ { FRAMEWORK_NAME}$ {SRCROOT} / build / Release-iphonesimulator / $ {FRAMEWORK_NAME} .framework / $ {FRAMEWORK_NAME}

#8
#复制模拟器的Swift模块映射进入
#框架。设备映射已存在于步骤6中。
#cp -r$ {SRCROOT} / build / Release-iphonesimulator / $ {FRAMEWORK_NAME} .framework / Modules / $ {FRAMEWORK_NAME} .swiftmodule /$ {HOME } / Desktop / $ {FRAMEWORK_NAME} .framework / Modules / $ {FRAMEWORK_NAME} .swiftmodule

#9
#删除最新版本。
if [-d$ {SRCROOT} / build];那么
rm -rf$ {SRCROOT} / build
fi

一旦您的框架在桌面上,如果您进入其中,将会有一个与您的框架同名的文本文档。如果你导航到那个并在终端上运行命令lipo -info,你应该得到以下输出:

 架构在胖文件中:MyFramework是:armv7 armv7s i386 x86_64 arm64 


I have an xcode framework project that I've created, which I can compile into a myframework.framework file. After compiling, I drag this framework into the Frameworks project folder of my application, and then to make use of classes from the framework I add the proper import statement to any class that needs it; this allows my app to successfully compile with references to classes defined in the framework. To get the app to deploy successfully to my device, I also add my custom framework to the "Embedded Binaries" section for my target. With all this in place, I can build my app from xcode and run it on my device.

My problem comes when I attempt to Archive my application for the app store. When I attempt to do this, I get a ton of compiler errors where xcode says it cannot find the declarations for any of the classes defined in my custom framework.

How can I set up Archive in xcode so that it properly references and embeds my custom framework?

解决方案

You actually don't need to put it in the "embedded binaries" section. You only need it in the "linked frameworks and libraries section. Make sure that your framework is a Universal Framework (meaning it can compile for all architectures), and make sure you have the right compiler flags set (-ObjC if your framework has any categories etc) There may be some other things you need to set as well like "Other C Flags" if your framework includes any c code and you want to enable bitcode in your client app then you should put "-fembed-bitcode" in your framework Other C Flags. Those were the things I needed to do to get my framework app to the store. I think its a just a misconception that you need to put this in embedded binaries as well to get it to archive for the store.

This is the build script I use to generate the universal framework. It builds right to my desktop. You can uncomment section 8 if your framework is in Swift. You want to create an aggregate target and add this as a run script in build phases.

# Merge Script

# 1
# Set bash script to exit immediately if any commands fail.
set -e

# 2
# Setup some constants for use later on.
FRAMEWORK_NAME="MyFramework"

# 3
# If remnants from a previous build exist, delete them.
if [ -d "${SRCROOT}/build" ]; then
rm -rf "${SRCROOT}/build"
fi

# 4
# Build the framework for device and for simulator (using
# all needed architectures).
xcodebuild -target "${FRAMEWORK_NAME}" -configuration Release -arch arm64 -arch armv7 -arch armv7s only_active_arch=no defines_module=yes -sdk "iphoneos"
xcodebuild -target "${FRAMEWORK_NAME}" -configuration Release -arch x86_64 -arch i386 only_active_arch=no defines_module=yes -sdk "iphonesimulator"

# 5
# Remove .framework file if exists on Desktop from previous run.
if [ -d "${HOME}/Desktop/${FRAMEWORK_NAME}.framework" ]; then
rm -rf "${HOME}/Desktop/${FRAMEWORK_NAME}.framework"
fi

# 6
# Copy the device version of framework to Desktop.
cp -r "${SRCROOT}/build/Release-iphoneos/${FRAMEWORK_NAME}.framework" "${HOME}/Desktop/${FRAMEWORK_NAME}.framework"

# 7
# Replace the framework executable within the framework with
# a new version created by merging the device and simulator
# frameworks' executables with lipo.
lipo -create -output "${HOME}/Desktop/${FRAMEWORK_NAME}.framework/${FRAMEWORK_NAME}" "${SRCROOT}/build/Release-iphoneos/${FRAMEWORK_NAME}.framework/${FRAMEWORK_NAME}" "${SRCROOT}/build/Release-iphonesimulator/${FRAMEWORK_NAME}.framework/${FRAMEWORK_NAME}"

# 8
# Copy the Swift module mappings for the simulator into the
# framework.  The device mappings already exist from step 6.
#cp -r "${SRCROOT}/build/Release-iphonesimulator/${FRAMEWORK_NAME}.framework/Modules/${FRAMEWORK_NAME}.swiftmodule/" "${HOME}/Desktop/${FRAMEWORK_NAME}.framework/Modules/${FRAMEWORK_NAME}.swiftmodule"

# 9
# Delete the most recent build.
if [ -d "${SRCROOT}/build" ]; then
rm -rf "${SRCROOT}/build"
fi

Once your framework is on the desktop, if you go inside of it there will be a text document with the same name as your framework. If you navigate to that and run the command "lipo -info" on it in terminal you should get the following output:

Architectures in the fat file: MyFramework are: armv7 armv7s i386 x86_64 arm64 

这篇关于如何归档包含自定义框架的应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆