StalkerRus
StalkerRus

Reputation: 411

CocoaPods adds duplicate project to xcworkspace

My workspace structure is the following:
-ProjectA
--ProjectB
--ProjectC
-Pods

I run the 'pod update' and what I get is
-ProjectA
--ProjectB
--ProjectC
-Pods
-ProjectB <- this should not be here!

My Podfile is:

platform :ios, '7.0'
inhibit_all_warnings!
workspace 'ProjectA'

target :ProjectA do
    pod "AFNetworking", "~> 2.0"
    pod 'Facebook-iOS-SDK'
    pod 'SDWebImage'
    pod 'FXBlurView'
    pod 'RESideMenu'
    pod 'RBStoryboardLink'
end

target :ProjectBTests do
    xcodeproj 'Libraries/ProjectB/ProjectB'
    pod 'Expecta'
    pod 'Specta'
    pod 'OCMock'
end

So is it possible to do anything with such behaviour?

Thanks!

Upvotes: 14

Views: 1829

Answers (3)

Anton Ogarkov
Anton Ogarkov

Reputation: 455

TLDR: This is a user's workspace bug. To fix the issue just open your workspace's contents.xcworkspacedata in a text editor and simplify all relative paths. E.g. OMGNotExistingDirectory/../FirstLibrary/FirstLibrary.xcodeproj should now look like FirstLibrary/FirstLibrary.xcodeproj

So, sometimes while rearranging your projects in a workspace your contents.xcworkspacedata may end up like this:

<?xml version="1.0" encoding="UTF-8"?>
<Workspace
   version = "1.0">
   <FileRef
      location = "group:App/App.xcodeproj">
   </FileRef>
   <FileRef
      location = "group:OMGNotExistingDirectory/../FirstLibrary/FirstLibrary.xcodeproj">
   </FileRef>
   <FileRef
      location = "group:SecondLibrary/SecondLibrary.xcodeproj">
   </FileRef>
   <FileRef
      location = "group:ThirdLibrary/ThirdLibrary.xcodeproj">
   </FileRef>
</Workspace>

See that OMGNotExistingDirectory/../FirstLibrary/FirstLibrary.xcodeproj ? Yes, that's the problem. Even if the folder in the path does not exist anymore the /.. part of the path allows XCode to ignore it and work without problems.

Now we run pod install. The problem here is when CocoaPods reassembles the workspace it compares relative paths instead of absolute to avoid duplicates. And, of course, FirstLibrary/FirstLibrary.xcodeproj is not OMGNotExistingDirectory/../FirstLibrary/FirstLibrary.xcodeproj even though they are pointing to the same file.

So to fix the issue you have to simplify the relative paths in your workspace by removing redundant parts in them.

Thanks to kezi's answer for giving a clue of where the issue is.

Upvotes: -1

keji
keji

Reputation: 5990

Replaced this line in lib/cocoapods/installer/user_project_integrator.rb #create_workspace:

new_file_references = file_references - workspace.file_references

with this code instead:

new_file_references = file_references - workspace.file_references    
absolute_paths = workspace.file_references.map { |fr| fr.absolute_path(workspace_path) }
new_file_references = new_file_references.select { |fr| absolute_paths.include? fr.absolute_path(workspace_path)  }

Basically use the absolute path to filter the items that have been added to the workspace already.

Upvotes: 2

bllakjakk
bllakjakk

Reputation: 5065

Please register it as a bug in coocoapods. The generated xcworkspace file is incorrect.

<?xml version="1.0" encoding="UTF-8"?>
<Workspace
   version = "1.0">
   <FileRef
      location = "group:ProjectA.xcodeproj">
   </FileRef>
   <FileRef
      location = "group:Pods/Pods.xcodeproj">
   </FileRef>
   <FileRef
      location = "group:ProjectA/ProjectB/ProjectB.xcodeproj">
   </FileRef>
</Workspace>

Upvotes: 1

Related Questions