Is there a way to copy bundle resource to app folder when built finished? - ios

Actually I have a xcode workspace, containing several projects, for example, projectA and projectB, projectA is the main project, and projectB will generate a bundle file which projectA will use, is there a way to copy the bundle file to the main app folder? I know one way to do this is to drag the generated bundle file here like the below image shows, but as we have several team members and use git to manage the project, this method will use my personal folder path, and when others want to build the project, they will have to drag the bundle again. Is there a way to copy the generated bundle using relative path? Or can I use a script to do this? So everyone can just checkout the code directly without dragging the bundle manually? Thanks.

In Target -> Build Phases can you just Run Script after that target is done to copy it to the other place?

Related

Using agvtool with multiple .xcodeproject files in one directory

I have tried using agvtool for ios build versionining. It works great when there is a single .xcodeproj file in the directory. In my case, our project structure is such that it has 4 .xcodeproj files in a single directory. When firing agvtool command in this directory it throws error message, 'agvtool does not work with multiple projects in the same directory'. Anyone has any idea how can I make agvtool work with this folder structure?
For people finding this post and using Fastlane, I just wanted to tell about the plugin https://github.com/SiarheiFedartsou/fastlane-plugin-versioning which have a increment_version_number_in_plist command which does not use agvtool (and support multiple .xcodeproj files in a single folder.
You just need to install the plugin above and replace your increment_version_number action with increment_version_number_in_plist .. they have a very similar contract.
For me, there were actually 2 xcode project files. i.e. projectName.xcodeproj and projectNameModule.xcodeproj. That happened as I removed some commits where we updated the project name from projectName to projectNameModule. For some reason even after reverting those name changes, the project *Module.xcodeproj and *Module.xcworkspace files were still existing.
I just deleted those unused files and it fixed the issue for me.

Automate copying resources from dependency project

I have a static library which
Creates .a file
Exports public headers
Creates a .bundle containing resources
I have a workspace containing my project which depends on this lib. Library is also part of the workspace. I am able to work out the build dependencies on .a file and public headers. For the bundle, I have to manually add/update the bundle to my applications copy bundle resources build phase.
I want to automate this such that the bundle created in the $(BUILT_PRODUCTS_DIR) gets copied in the application bundle.
Is there a way to do this, may be a run script?
Appreciate your help.
Figured it out.
I added a run script phase to my application. Script to copy the generated bundle to my application,
cp -R ${BUILT_PRODUCTS_DIR}/Mybundle.bundle ${BUILT_PRODUCTS_DIR}/${PRODUCT_NAME}.app/Mybundle.bundle
Hope this helps!

Include files in bundle only for simulator

I have a couple test files I'd like be included in the bundle but ONLY when the project is compiled to be run in the simulator.
Is there a flag/target/setting somewhere in Xcode to indicate certain files shouldn't be included in the bundle for different schemes?
What you need to do is not include the files in the standard build phase "Copy Files" block, but write a custom build script that examines the current platform (EFFECTIVE_PLATFORM_NAME -iphonesimulator), and copies the files only in that case. Create a custom Run Script and the variables get printed out to the build log - you can examine all your options there.

How can I get my project's folder structure to be mirrored in Finder?

I have an Xcode (4.2) project with a bunch of class files, and I have them neatly organized into folders. These folder aren't "real", however; in Finder, my classes are all just dumped into the one "Classes" folder. Is there any way to get the virtual folder structure I see in Xcode to be reflected in the real Finder folder structure? Or do I have to do this manually?
https://github.com/venmo/synx
A command-line tool that reorganizes your Xcode project folder to match your Xcode groups
Installation
$ gem install synx
Usage
Basic
:warning: WARNING: Make sure that your project is backed up through source control before doing anything :warning:
Execute the command on your project to have it reorganize the files on the file system:
$ synx path/to/my/project.xcodeproj
It may have confused CocoaPods. If you use them, execute this command:
$ pod install
You're good to go!
Advanced
Synx supports the following options:
--prune, -p remove source files and image resources that are not referenced by the the Xcode project
--no-color removes all color from the output
--no-default-exclusions doesn't use the default exclusions of /Libraries, /Frameworks, and /Products
--quiet, -q silence all output
--exclusion, -e EXCLUSION ignore an Xcode group while syncing
For example, OCMock could have been organized using this command:
$ synx -p -e "/OCMock/Core Mocks" -e /OCMockTests Source/OCMock.xcodeproj/
if they had wanted not to sync the /OCMock/Core Mocks and /OCMockTests groups, and also remove (-p) any image/source files found by synx that weren't referenced by any groups in Xcode.
I often want to do the same thing, but as far as I know there is no automatic way to do it, you have to do it manually unfortunately...
There is no 'automatic' way to make the XCode file pane structure automagically conform to the finder folder structure, although I agree there should be a setting for this.
I follow these steps when making a project:
Create the project.
Delete by reference any files I want to move.
Open finder and move the files, then drag them back into XCode.
When adding new files:
Create a folder in finder if needed.
Drag the folder into XCode.
Right-click and make a new file on the group that represents the folder just dragged in.
If you're using git, it's a little more work:
Commit your project before making a folder or file deletions/moves.
Delete them by reference from XCode.
Move them in finder.
Using terminal, type git mv sourcePath destPath to move files or git rm sourcePath to delete them.
Then drag back into XCode.
You can see more about my frustration with learning git here:
How can I move files & folders using git in Xcode 4?

Xcode linked project header files not found

Here is the situation I have:
ProjectA - Xcode static library project.
ProjectA contains logical code group ExternLib with file ExternLib.h. ExternLib.h itself is in the folder Classes/lib/ExternLib (relative to ProjectA folder). Within ProjectA, I use ExternLib.h simply as: #import "ExternLib.h". This works fine.
Next I have ProjectB. This includes ProjectA as a linked Xcode project. The target has been added correctly etc. However, when I include a file in ProjectB which in turn includes ExternLib.h, upon building ProjectB, I get an error saying that the file ExternLib.h cannot be found.
I have tried adding the path to ExternLib.h to the header search path (all types: relative, absolute, with recursion etc.) but to no avail. I have checked that static library target has the copy headers step and the file ExternLib.h is included in it.
Anybody able to shed some light on how to get around this?
Add a Run Script Build Phase to the target for ExternLib that executes
mkdir -p "${BUILT_PRODUCTS_DIR}ExternLibHeaders"
Add a Copy Files build phase that copies the ExternLib header files into ${BUILT_PRODUCTS_DIR}ExternLibHeaders, and add all of ExternLib's headers into that phase.
In the app target for ProjectB, add ${BUILT_PRODUCTS_DIR}/ExternLibHeaders/ to the Header Search Paths for all configurations.
In Xcode > Preferences > Build, set the Build Products Directory to some common location.
The fourth step is crucial; it ensures that BUILT_PRODUCTS_DIR is the same for both projects.
It's really hard to say what might have gone wrong.
I'd start from scratch with a tutorial on building and using static libraries, and see if any of the steps jog any ideas out of you.

Resources