私のプロジェクトでは、CocoaPodsとカスタムxcconfig
ファイルを使用しています。これまで、これによって問題が発生することはありませんでした#include
。カスタム構成の最後に、CocoaPodsで生成された構成を実行する必要がありました。
ただし、にOTHER_LDFLAGS
基づいて条件付きで指定する必要があるという問題が発生しましたが、xcconfig
これを行う方法がわかりません。
最初に、OTHER_LDFLAGS
このように単純にログを記録しようとしましたが、フラグは実際にはログに記録されません。
post_install do |installer_representation|
installer_representation.project.targets.each do |target|
target.build_configurations.each do |config|
name = target.name
puts "Target Found: #{name}"
flags = config.build_settings['OTHER_LDFLAGS']
puts "OTHER_LDFLAGS Found: #{flags}"
end
end
end
出力は次のようになります。
Target Found: Pods-ProjectName-DependencyName1
OTHER_LDFLAGS Found: # nothing here...?
Target Found: Pods-ProjectName-DependencyName2
OTHER_LDFLAGS Found: # again nothing...
# etc...
Target Found: Pods-ProjectName # Cool, this is the main target pod
OTHER_LDFLAGS Found: # ...
OTHER_LDFLAGS
CocoaPodsのインストール後フックを介して実際に変更するにはどうすればよいですか?
私は同じ問題に出くわしました。最初に私OTHER_LDFLAGS
は明白なことで修正しようとしました:
post_install do |installer|
installer.pods_project.targets.each do |target|
if target.name == "Pods-SomeTarget"
puts "Updating #{target.name} OTHER_LDFLAGS"
target.build_configurations.each do |config|
config.build_settings['OTHER_LDFLAGS'] ||= ['$(inherited)']
config.build_settings['OTHER_LDFLAGS'] << '-l"AFNetworking"'
end
end
end
end
しかし、それは機能しませんでした。関連するxcconfigは変更を取得しませんでした。最終的に、うまく機能する回避策を見つけました。まず、post_intall
フック内の関連するxcconfigファイルの内容を読み取り、変更して、書き戻します。
v1.0
post_install do |installer|
installer.pods_project.targets.each do |target|
if target.name == "Pods-SomeTarget"
puts "Updating #{target.name} OTHER_LDFLAGS"
target.build_configurations.each do |config|
xcconfig_path = config.base_configuration_reference.real_path
xcconfig = File.read(xcconfig_path)
new_xcconfig = xcconfig.sub('OTHER_LDFLAGS = $(inherited)', 'OTHER_LDFLAGS = $(inherited) -l"AFNetworking"')
File.open(xcconfig_path, "w") { |file| file << new_xcconfig }
end
end
end
end
編集:v1.0からの改善。xcconfigString
コンテンツを直接操作する代わりに、xccconfigをbuild_configurationに読み込みHash
、ハッシュを変更してからxcconfigにフラッシュします。
v1.5
post_install do |installer|
installer.pods_project.targets.each do |target|
if target.name == "Pods-SomeTarget"
puts "Updating #{target.name} OTHER_LDFLAGS"
target.build_configurations.each do |config|
xcconfig_path = config.base_configuration_reference.real_path
# read from xcconfig to build_settings dictionary
build_settings = Hash[*File.read(xcconfig_path).lines.map{|x| x.split(/\s*=\s*/, 2)}.flatten]
# modify OTHER_LDFLAGS
build_settings['OTHER_LDFLAGS'] << '-l"AFNetworking"'
# write build_settings dictionary to xcconfig
build_settings.each do |key,value|
File.open(xcconfig_path, "a") {|file| file.puts key = value}
end
end
end
end
end
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加