如何在主项目 xcode 4.1 中包含一个包
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6690080/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to include a bundle in main project xcode 4.1
提问by Leonardo
[UPDATE 03/04/2015]
[更新 03/04/2015]
The question is now 4 years old, and applies to a specific version of XCode which I have now specified in the subject.
这个问题现在已有 4 年历史,适用于我现在在主题中指定的特定版本的 XCode。
I have searched a lot for this argument, but I couldn't find a solution, I even post on stackoverflow, but I soon deleted the question becuase of very little access. Now I am trying again.
我为这个论点搜索了很多,但找不到解决方案,我什至在stackoverflow上发帖,但由于访问量很少,我很快就删除了该问题。现在我再试一次。
I have a workspace with two distinct projects A and B.
我有一个包含两个不同项目 A 和 B 的工作区。
B has two targets, one that build a static library Blib.a, and one that build a bundle B.bundle. All of them get built in the derived directory.
B 有两个目标,一个构建静态库 Blib.a,一个构建包 B.bundle。所有这些都构建在派生目录中。
In project A I can easily add the static library from the build phases. However I cannot find a way to include the bundle. B.bundle is not visible from "copy resource" tab in A. Therefore I need to add manually, with all that implies. I also thought about using a script, but I would like to use this as a very last option.
在项目中,AI 可以轻松地从构建阶段添加静态库。但是我找不到包含捆绑包的方法。B.bundle 在 A 中的“复制资源”选项卡中不可见。因此,我需要手动添加,包括所有这些。我也考虑过使用脚本,但我想将其用作最后的选择。
Has someone a solution for this ? Did I miss something ?
有人对此有解决方案吗?我错过了什么 ?
thanks
谢谢
采纳答案by Leonardo
After long investigation, it came up there's no easy way of doing this. The B.bundle is never visible to A project, and there's no settings in workspace to change that. At this point there are three solutions:
经过长时间的调查,发现没有简单的方法可以做到这一点。B.bundle 永远不会对 A 项目可见,并且工作区中没有设置可以更改它。此时有三种解决方案:
- Include the bundle manually from "copy resources->other", I started with this, but everytime there's a change you have to drop and include the bundle again
- Create a script to be run in build phase, if everything is built into the PRODUCTS dir you can find the bundle easily and having copied automatically into the app.bundle. This is not a bad solution. If you are using svn the script got included in project, and users have it for free without additional work.
- As suggested by Apple tech support, use folder references.Build bundle B into a folder and add such folder to project A using the "Create Folder References for any added folders" option. Xcode 4 will update your bundle into that folder every time you built it. The added folder will appear as blue once included in your project A.
- 从“复制资源->其他”手动包含包,我从这个开始,但每次有更改时,您都必须删除并再次包含包
- 创建要在构建阶段运行的脚本,如果所有内容都内置到 PRODUCTS 目录中,您可以轻松找到捆绑包并自动复制到 app.bundle 中。这不是一个糟糕的解决方案。如果您使用 svn,该脚本将包含在项目中,用户无需额外工作即可免费获得它。
- 按照 Apple 技术支持的建议,使用文件夹引用。将包 B 构建到文件夹中,并使用“为任何添加的文件夹创建文件夹引用”选项将此类文件夹添加到项目 A。每次构建时,Xcode 4 都会将您的包更新到该文件夹中。一旦包含在您的项目 A 中,添加的文件夹将显示为蓝色。
Thats's it, I personally use the script, because this solution is path independent if you use standard xcode reference variable such as BUILT_PRODUCTS_DIR and so on, and the shell script is just a cp -r-f
就是这样,我个人使用脚本,因为如果您使用标准 xcode 引用变量(例如 BUILT_PRODUCTS_DIR 等),则此解决方案与路径无关,而 shell 脚本只是一个 cp -rf
[UPDATE 03/04/2015]
[更新 03/04/2015]
I would like to point out that the question is now 4 years old. At that time there weren't many "official" options available. I even spoke with Apple Tech Support, which proposed solution 3 as the only available solution. It is of course very likely that things are now changed, and there is a much better solution. Just to speak, I also like to add that the three above are not "hacks" but "solutions", maybe technically outdated, but they can still be used nowadays. I intend a "hack" as a..."hack", which means it probably not going to work in future software release.
我想指出这个问题现在已有 4 年历史了。当时没有多少“官方”选项可用。我什至与 Apple 技术支持进行了交谈,他们建议将解决方案 3 作为唯一可用的解决方案。当然,现在情况很可能发生了变化,并且有更好的解决方案。顺便说一下,我还想补充一点,以上三个不是“黑客”而是“解决方案”,也许技术上已经过时,但现在仍然可以使用。我打算将“hack”作为...“hack”,这意味着它可能不会在未来的软件版本中起作用。
回答by 0xced
Here is how I did it.
这是我如何做到的。
Drag and drop
B.bundle
from Project B → Products → B.bundle into the Copy Bundle Resourcesbuild phase of your app in Project A (select the Create groupsoptions when asked). This will addB.bundle
at the root of your Project A outline. You can move it into the Frameworksdirectory nearBlib.a
if it you prefer.Select
B.bundle
and check its Locationin the Identity and Typeright panel (Utilities area). By default, Xcode chooses Relative to Project. This is wrong, select Relative to Build Productsinstead.The path to
B.bundle
will now look something like../../../../../../../../Projects/MyApp/B.bundle
. This is not what you want, but you can easily fix it. OpenProjectA.xcodeproj/project.pbxproj
in a text editor, search for this path and delete everything in it except forB.bundle
. Yourproject.pbxproj
should look like this:explicitFileType = wrapper.cfbundle; name = B.bundle; path = "B.bundle"; sourceTree = BUILT_PRODUCTS_DIR; };
Save your
project.pbxproj
file. Xcode will automatically reload your project and your app should build just fine.
拖放
B.bundle
从项目B→产品→B.bundle到复制包资源在项目A你的应用程序的构建阶段(选择创建组当被问及选项)。这将添加B.bundle
到项目 A 大纲的根部。如果您愿意,可以将其移动到附近的Frameworks目录中Blib.a
。在Identity and Type右侧面板(Utilities 区域)中选择
B.bundle
并检查其位置。默认情况下,Xcode 选择相对于项目。这是错误的,改为选择相对于构建产品。到的路径
B.bundle
现在看起来像../../../../../../../../Projects/MyApp/B.bundle
. 这不是您想要的,但您可以轻松修复它。ProjectA.xcodeproj/project.pbxproj
在文本编辑器中打开,搜索此路径并删除其中除B.bundle
. 你project.pbxproj
应该是这样的:explicitFileType = wrapper.cfbundle; name = B.bundle; path = "B.bundle"; sourceTree = BUILT_PRODUCTS_DIR; };
保存您的
project.pbxproj
文件。Xcode 将自动重新加载您的项目,您的应用程序应该可以正常构建。
回答by agarcian
After searching for a long time and failing many times, I found this resource that has been an absolutely great tutorial to create Static Libraries and include bundles in your main project or even for distribution to 3rd party developers that may consume your library.
在搜索了很长时间并失败了很多次之后,我发现这个资源是一个非常好的教程,可以创建静态库并在您的主项目中包含包,甚至分发给可能使用您的库的 3rd 方开发人员。
Absolutely recommended:
绝对推荐:
回答by Vladimir Borodko
As of Xcode 5.1.1 I was able to drag and drop B.bundle from the Project Navigator to the Copy Bundle Resources list of project A Build Phases. I assume creating B.bundle target is not an issue.
从 Xcode 5.1.1 开始,我可以将 B.bundle 从 Project Navigator 拖放到项目 A Build Phases 的 Copy Bundle Resources 列表中。我认为创建 B.bundle 目标不是问题。
回答by Joshua Nozzi
In project A, is the product of project B a dependency in your scheme's Build action? I think you might have to set up this dependency (sometimes disabling the automatic dependency discovery option is best) for it to show up and be available for copying into another target. I believe this is because it doesn't really exist (like an image resource file) until it's built and Xcode needs to ensure it's built before working with it from another target.
在项目 A 中,项目 B 的产品是您方案的构建操作中的依赖项吗?我认为您可能必须设置此依赖项(有时最好禁用自动依赖项发现选项)才能显示并复制到另一个目标中。我相信这是因为它在构建之前并不真正存在(如图像资源文件),并且 Xcode 需要确保在从另一个目标使用它之前构建它。
回答by vadimtrifonov
- Switch build to
Generic iOS Device
. This step is needed to create a non-simulator reference. - Drag the
.bundle
to the other project'sCopy Bundle Resources
. - Select the
.bundle
in theProject navigator
of the other project, and change itsLocation
toRelative to Build Products
- 将构建切换到
Generic iOS Device
. 创建非模拟器引用需要此步骤。 - 将 拖到
.bundle
另一个项目的Copy Bundle Resources
. - 选择
.bundle
在Project navigator
其他项目中,并改变其Location
对Relative to Build Products
Make sure your
.bundle
in added toTarget Dependencies
of your static library
确保您
.bundle
添加到Target Dependencies
您的静态库