Last active
November 17, 2020 07:50
-
-
Save falcon11/6c3233641a8d40fdfdc7b271eb979ae7 to your computer and use it in GitHub Desktop.
Cocoapods Podfile remove subproject's static library and static framework from other linker flag
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
post_install do |installer| | |
# main project pod target | |
applicationTargets = [ | |
'Pods-Mall', | |
] | |
embedded_targets = installer.aggregate_targets.select { |aggregate_target| | |
!(applicationTargets.include? aggregate_target.name) | |
} | |
embedded_pod_targets = embedded_targets.flat_map { |embedded_target| embedded_target.pod_targets } | |
host_targets = installer.aggregate_targets.select { |aggregate_target| | |
applicationTargets.include? aggregate_target.name | |
} | |
host_pod_targets = host_targets.flat_map { |host_target| host_target.pod_targets } | |
# remove static library and static framework from embedded_targets | |
embedded_targets.each do |embedded_target| | |
embedded_target.xcconfigs.each do |config_name, config_file| | |
embedded_target.pod_targets.each do |pod_target| | |
if host_pod_targets.include? pod_target | |
pod_target.specs.each do |spec| | |
if spec.attributes_hash['ios'] != nil | |
frameworkPaths = spec.attributes_hash['ios']['vendored_frameworks'] | |
elsif spec.attributes_hash['vendored_libraries'] | |
libraryPaths = spec.attributes_hash['vendored_libraries'] | |
else | |
frameworkPaths = spec.attributes_hash['vendored_frameworks'] | |
end | |
if frameworkPaths != nil | |
frameworkNames = Array(frameworkPaths).map(&:to_s).map do |filename| | |
extension = File.extname filename | |
File.basename filename, extension | |
end | |
frameworkNames.each do |name| | |
puts "Removing framework #{name} from OTHER_LDFLAGS of target #{embedded_target.name}" | |
config_file.frameworks.delete(name) | |
end | |
end | |
if libraryPaths != nil | |
libraryNames = Array(libraryPaths).map(&:to_s).map do |filename| | |
extension = File.extname filename | |
name = File.basename filename, extension | |
name = name.delete_prefix('lib') | |
end | |
libraryNames.each do |name| | |
puts "Removing library #{name} from OTHER_LDFLAGS of target #{embedded_target.name}" | |
config_file.libraries.delete(name) | |
end | |
end | |
if spec.attributes_hash['static_framework'] == true | |
config_file.frameworks.delete(spec.name) | |
end | |
end | |
end | |
end | |
xcconfig_path = embedded_target.xcconfig_path(config_name) | |
config_file.save_as(xcconfig_path) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment