I got a crash on my Xcode with the following message, while I'm trying to run some UITests !
I tried multiple solutions : 1- I've added this piece of code to my podfile, that someone had suggested it on another question or article on the Internet
def remove_duplicated_frameworks(app_pod_name, installer)
test_targets = get_test_targets(app_pod_name, installer)
puts "Detected test targets: #{test_targets}"
puts "Removing duplicated frameworks from OTHER_LDFLAGS"
targets = installer.aggregate_targets.select { |x| !test_targets.include?(x.name) }
# Checks each pair of targets if they have common pods. Duplicates are removed from the first one's xcconfig.
for i in 0..targets.size-1 do
target = targets[i]
remainingAppPodTargets = targets[i+1..targets.size-1].flat_map(&:pod_targets)
target.xcconfigs.each do |config_name, config_file|
# Removes all frameworks which exist in other pods
remainingAppPodTargets
.flat_map { |pod_target| get_framework_names(pod_target) }
.each { |framework| config_file.frameworks.delete(framework) }
# Saves updated xcconfig
xcconfig_path = target.xcconfig_path(config_name)
config_file.save_as(xcconfig_path)
end
end
end
def get_test_targets(app_pod_name, installer)
main_target_name = app_pod_name.gsub("Pods-", "")
installer.aggregate_targets
.find { |x| x.name == app_pod_name }
.user_project
.targets
.select { |x| x.test_target_type? }
.flat_map { |x| ["Pods-#{x}", "Pods-#{main_target_name}-#{x}"] }
.select { |x| installer.aggregate_targets.map(&:name).include?(x) }
.uniq
end
def get_framework_names(pod_target)
frameworkNames = pod_target.specs.flat_map do |spec|
# We should take framework names from 'vendored_frameworks'.
# If it's not defined, we use 'spec.name' instead.
#
# spec.name can be defined like Framework/Something - we take the first part
# because that's what appears in OTHER_LDFLAGS.
frameworkPaths = unless spec.attributes_hash['ios'].nil?
then spec.attributes_hash['ios']['vendored_frameworks']
else spec.attributes_hash['vendored_frameworks']
end || [spec.name.split(/\//, 2).first]
map_paths_to_filenames(frameworkPaths)
end
frameworkNames.uniq
end
def map_paths_to_filenames(paths)
Array(paths).map(&:to_s).map do |filename|
extension = File.extname filename
File.basename filename, extension
end
end
2- The first solution didn't work so I tried to replace it with this piece of code, and run "pod install" and nothing happens too
sharedLibrary = installer.aggregate_targets.find { |aggregate_target| aggregate_target.name == 'Pods-[MY_FRAMEWORK_TARGET]' }
installer.aggregate_targets.each do |aggregate_target|
if aggregate_target.name == 'Pods-[MY_APP_TARGET]'
aggregate_target.xcconfigs.each do |config_name, config_file|
sharedLibraryPodTargets = sharedLibrary.pod_targets
aggregate_target.pod_targets.select { |pod_target| sharedLibraryPodTargets.include?(pod_target) }.each do |pod_target|
pod_target.specs.each do |spec|
frameworkPaths = unless spec.attributes_hash['ios'].nil? then spec.attributes_hash['ios']['vendored_frameworks'] else spec.attributes_hash['vendored_frameworks'] end || Set.new
frameworkNames = Array(frameworkPaths).map(&:to_s).map do |filename|
extension = File.extname filename
File.basename filename, extension
end
end
frameworkNames.each do |name|
if name != '[DUPLICATED_FRAMEWORK_1]' && name != '[DUPLICATED_FRAMEWORK_2]'
raise("Script is trying to remove unwanted flags: #{name}. Check it out!")
end
puts "Removing #{name} from OTHER_LDFLAGS"
config_file.frameworks.delete(name)
end
end
end
xcconfig_path = aggregate_target.xcconfig_path(config_name)
config_file.save_as(xcconfig_path)
end
end
3- For this solution I tried to make use_frameworks!
a globale in my podfile, but didn't work either !
I still have the same crash and my UITests don't work !
Any help please ?