6

I am trying to exclude some .swift and .storyboard files from my project (Xcode9) for release build using EXCLUDED_SOURCE_FILE_NAMES. But its not working for me.

Is it possible to give any folder name to exclude it completely? How to give multiple files and folder name?

It is not working if I give path like ../ForlderName/*.

Folder is at the same level as my project.

Is it possible to exclude sub-folders files as well?

I am able to exclude if my hierarchy is

MyProject Folder
 |_
   MyProject Folder 
    |_FolderToBeExcluded

If I gave FolderToBeExcluded/* it is working but file in FolderToBeExcluded's subfolders are not getting excluded.

If my heirachy is like this (ie folder to be excluded and project folder both at same level)

FolderToBeExcluded
MyProject Folder
 |_
   MyProject Folder

If I give ../FolderToBeExcluded/ or $(SRCROOT)/../FolderToBeExcluded/ both are not working

If I give directly any one of the file name which is to be excluded it is getting exclude without giving full path.

Is it the limitation of EXCLUDED_SOURCE_FILE_NAMES?

srus2017
  • 394
  • 2
  • 14
  • Probably duplicate of https://stackoverflow.com/questions/7536908/how-do-i-use-excluded-source-file-names-in-xcode-4-ios – matt Mar 20 '18 at 00:21
  • See also http://twobitlabs.com/2012/01/excluding-files-from-production-xcode-builds/ etc. – matt Mar 20 '18 at 00:21
  • these links are not solving my problem. I already seen them. I don't want to give every file name. – srus2017 Mar 20 '18 at 12:43
  • I am able to exclude if I give individual file name. – srus2017 Mar 20 '18 at 13:08
  • You can call it “the limitation” if you like. But anyhow, that is how it works, and it sounds like you understand it perfectly. So there is no real question to ask. This is just a way of complaining that it doesn’t work in some other way. In that case, SO is inappropriate. File a bug with Apple instead. – matt Mar 20 '18 at 13:57

5 Answers5

2

If I gave FolderToBeExcluded/* it is working but file in FolderToBeExcluded's subfolders are not getting excluded.

The reason subfolders are not excluded is because of the /*. That tells it to look for files in FolderToBeExcluded. If you just give FolderToBeExcluded (no slash after) then it will exclude all files in that folder and all subfolders. At least that is what I found.

Jason
  • 29
  • 2
  • 6
    This did not work for me using Xcode 12.2. I had to do `FolderToBeExcluded/*` and `FolderToBeExcluded/*/*` (as the folder had subfolders). – Frederik Oct 20 '20 at 08:23
  • This DID work for me in Xcode 12.5 — I simply wrote the folder name `FolderToBeExcluded` with no `/` or `*`. – Robin Stewart May 11 '21 at 23:31
1

An important gotcha I ran into today is that you can't exclude files within a folder reference, but you can exclude an entire referenced folder.

When you add a folder to Xcode it will ask you if you want to create a group or create a folder reference. If you choose the second option, then you'll need to be aware that you can't exclude files within the folder, but you can exclude the entire folder.

David Olesch
  • 151
  • 1
  • 3
1

My Findings

Lets say

Project
|_ Foo
   |_ Bar
      |_ ToBeExcluded
         |  file.json
         |_ Sub
            |_ subfile.json

I tried ToBeExcluded/* which works excludes file.json but not subfile.json

When trying ToBeExcluded/ and ToBeExcluded the exclusions seems to be ignored as both files are still included

ToBeExcluded/** excludes file.json but includes subfile.json (this is suppose to be recursive but hey)

ToBeExcluded/*/* excludes subfile.json but includes file.json (makes sense I guess)

Kamen suggested using $(SRCROOT) so I tried $(SRCROOT)/Foo/Bar/ToBeExcluded/*.* (which is the same as just $(SRCROOT)/Foo/Bar/ToBeExcluded/*) and it does the same as ToBeExcluded/*, same goes for all other variants and the behaving the same with full path versus without

${PROJECT_DIR} (in my case) translated to the same thing as $(SRCROOT)so did the same thing sadly

My Conclusion (For now)

Sadly for now I think what Im going to do is just exclude ToBeExcluded/* and maybe ToBeExcluded/*/* (will think on this) then just make sure that whenever adding new files to it that preferably in that root folder and if need be grouped in xcode without creating a folder. Worst case a single level of subfolder can be added

0

For me it worked if I define the value of EXCLUDED_SOURCE_FILE_NAMES like this:

$(SRCROOT)/../FolderToBeExcluded/*.*

I am using Xcode 9.4.1

Kamen Goranchev
  • 1,836
  • 1
  • 23
  • 27
0

This seems to be the only solution:

  1. Use groups without folders for every subfolder in excluded directory
  2. Exclude ${PROJECT_DIR}/{Path to Excluded Folder}/* in EXCLUDED_SOURCE_FILE_NAMES settings
Feridun Erbaş
  • 573
  • 1
  • 6
  • 19