s.resource_bundles = {
'MyBundle' => ['Assets/folder_reference_to_be_preserved/*']
}
I have a special need for a folder reference inside a resource bundle.. Right now, all of the files from within this folder will be included in MyBundle but they will be added on root level (within a group).. but I need them inside a folder reference(blue icon in Xcode)
I'm not entirely sure I follow, but is spec.preserve_paths what you are looking for?
After running pod install the resource_bundles directive will create a new target called Pods-MyBundle
This target will contain all the files in the mentioned path Assets/folder_reference_to_be_preserved/* something like this:
https://www.dropbox.com/s/6057mxbjyug67nd/Screenshot%202015-05-07%2015.04.04.png?dl=0
However, i need to also preserve a subfolder that is found at Assets/folder_reference_to_be_preserved/subfolder like this:
https://www.dropbox.com/s/sn3z8w18hcd9yho/Screenshot%202015-05-07%2015.05.17.png?dl=0
If I would manually add the folder, I would check the Create folder references rather than Create groups
Does this make more sense?
Maybe there is a way to add this in the post_install step? Maybe in combination with preserve_paths?
I've managed to find a solution myself. Edit your Podfile to this
post_install do |installer|
installer.project.targets.each do |target|
target.build_configurations.each do |config|
if target.name == "TargetWhereToAddTheFolderOrFileReference"
source_files = target.source_build_phase.files
folderReference = installer.project.add_file_reference("/AbsolutePath/To/FileOrFolder", installer.project.pod_group("PodGroupWhereToAddTheFileOrFolder"), true)
target.source_build_phase.add_file_reference(btsdata, true)
end
end
end
end
@cipriamcaba I tried your script, but it is not working for me. I am running cocoapods 0.39. I changed the "project" to "pod_projects" because I believe that was changed in version 0.39.
Also, how we enable the puts method to work? I was trying to debug it, but nothing.
Nevermind. I had another post_install in my podfile. I seems I can only have one.
Option 1: You can just add an NSBundle to the target and it'll preserve your paths. An example of this is on https://github.com/iwasrobbed/Down/blob/master/Down.podspec#L20
It has a need to do so for JS/CSS files that are referenced from an HTML file: https://github.com/iwasrobbed/Down/tree/master/Resources/DownView.bundle
Option 2: An updated version of the script above (for scenarios like React Native where you can't use NSBundle)
def my_custom_post_install(installer)
project = installer.pods_project
project.targets.each do |target|
target.build_configurations.each do |config|
if target.name == "MyCustomTarget"
file_ref = project.add_file_reference("#{Dir.pwd}/Relative/Path/To/Assets", project.pod_group("MyCustomTarget"), false)
target.add_resources([file_ref])
end
end
end
end
and you'd add that to a _single_ post_install hook (because you can only have one) at the bottom of your Podfile like:
post_install do |installer|
my_custom_post_install(installer)
end
spec.resources = ['Assets/folder_reference_to_be_preserved']
# without any wild like '/', '/*.*', '/**/*.*'
This works.
spec.resources = ['path/folder/**']
all the subfolder in folder will be blue icon
To still use dynamic bundle target from Cocoapods, you can provide an folder path or array of paths. If a path to a folder is provided, it will preserve that folder.
s.resource_bundles = {
'MyBundle' => [
'Assets/**/*.{storyboard,xib,xcassets,json,imageset,png,lproj}'
'Assets/folder_reference_to_be_preserved/'
]
}
Most helpful comment
spec.resources = ['path/folder/**']
all the subfolder in folder will be blue icon