|
11 | 11 | project_path = Dir.glob("#{current_path}/ios/*.xcodeproj").first
|
12 | 12 | file_name = File.basename(project_path, ".xcodeproj")
|
13 | 13 | project_location = "./ios/#{file_name}.xcodeproj"
|
14 |
| -target_name = file_name |
| 14 | +default_target_name = file_name |
15 | 15 | framework_root = '../node_modules/instabug-reactnative/ios'
|
16 | 16 | framework_name = 'Instabug.framework'
|
17 | 17 |
|
|
25 | 25 | project = Xcodeproj::Project.open(project_location)
|
26 | 26 | frameworks_group = project.groups.find { |group| group.display_name == 'Frameworks' }
|
27 | 27 | frameworks_group ||= project.new_group('Frameworks')
|
28 |
| -target = project.targets.find { |target| target.to_s == target_name } |
29 |
| -frameworks_build_phase = target.build_phases.find { |build_phase| build_phase.to_s == 'FrameworksBuildPhase' } |
30 |
| - |
31 |
| -# Add new "Embed Frameworks" build phase to target |
32 |
| -embed_frameworks_build_phase = target.build_phases.find { |build_phase| build_phase.to_s == 'Embed Instabug Framework'} |
33 |
| -Kernel.exit(0) if embed_frameworks_build_phase |
34 |
| -embed_frameworks_build_phase = project.new(Xcodeproj::Project::Object::PBXCopyFilesBuildPhase) |
35 |
| -embed_frameworks_build_phase.name = 'Embed Instabug Framework' |
36 |
| -embed_frameworks_build_phase.symbol_dst_subfolder_spec = :frameworks |
37 |
| -target.build_phases << embed_frameworks_build_phase |
38 |
| - |
39 |
| -# Add framework search path to target |
40 |
| -target.build_configurations.each do |config| |
41 |
| - framework_search_paths = target.build_settings(config.name)['FRAMEWORK_SEARCH_PATHS'] |
42 |
| - |
43 |
| - framework_search_paths ||= ['$(inherited)'] |
44 |
| - framework_search_paths = [framework_search_paths] unless framework_search_paths.is_a?(Array) |
45 |
| - framework_search_paths << framework_root unless framework_search_paths.include? framework_root |
46 |
| - |
47 |
| - target.build_settings(config.name)['FRAMEWORK_SEARCH_PATHS'] = framework_search_paths |
48 |
| -end |
49 |
| - |
50 |
| -# Add framework to target as "Embedded Frameworks" |
| 28 | +default_target = project.targets.find { |target| target.to_s == default_target_name } |
| 29 | +targets = project.targets |
51 | 30 | framework_ref = frameworks_group.new_file("#{framework_root}/#{framework_name}")
|
52 |
| -build_file = embed_frameworks_build_phase.add_file_reference(framework_ref) |
53 |
| -frameworks_build_phase.add_file_reference(framework_ref) |
54 |
| -build_file.settings = { 'ATTRIBUTES' => ['CodeSignOnCopy', 'RemoveHeadersOnCopy'] } |
55 | 31 |
|
| 32 | +# Add Instabug to every target that is of type application |
| 33 | +targets.each do |target| |
| 34 | + if target.is_a? Xcodeproj::Project::Object::PBXNativeTarget and (target.product_type == "com.apple.product-type.application") and (target.platform_name == :ios) |
| 35 | + |
| 36 | + # Add new "Embed Frameworks" build phase to target |
| 37 | + embed_frameworks_build_phase = target.build_phases.find { |build_phase| build_phase.to_s == 'Embed Instabug Framework'} |
| 38 | + Kernel.exit(0) if embed_frameworks_build_phase |
| 39 | + embed_frameworks_build_phase = project.new(Xcodeproj::Project::Object::PBXCopyFilesBuildPhase) |
| 40 | + embed_frameworks_build_phase.name = 'Embed Instabug Framework' |
| 41 | + embed_frameworks_build_phase.symbol_dst_subfolder_spec = :frameworks |
| 42 | + target.build_phases << embed_frameworks_build_phase |
| 43 | + |
| 44 | + # Add static library to non default targets' build phase |
| 45 | + if target.name != default_target_name |
| 46 | + static_library_file_reference = default_target.frameworks_build_phase.files_references.find { |file_reference| file_reference.path == 'libRNInstabug.a' } |
| 47 | + target.frameworks_build_phase.add_file_reference(static_library_file_reference) |
| 48 | + end |
| 49 | + |
| 50 | + # Add framework search path to target |
| 51 | + target.build_configurations.each do |config| |
| 52 | + framework_search_paths = target.build_settings(config.name)['FRAMEWORK_SEARCH_PATHS'] |
| 53 | + |
| 54 | + framework_search_paths ||= ['$(inherited)'] |
| 55 | + framework_search_paths = [framework_search_paths] unless framework_search_paths.is_a?(Array) |
| 56 | + framework_search_paths << framework_root unless framework_search_paths.include? framework_root |
56 | 57 |
|
57 |
| -#Add New Run Script Phase to Build Phases |
58 |
| -phase = target.new_shell_script_build_phase(INSTABUG_PHASE_NAME) |
59 |
| -phase.shell_script = INSTABUG_PHASE_SCRIPT |
| 58 | + target.build_settings(config.name)['FRAMEWORK_SEARCH_PATHS'] = framework_search_paths |
| 59 | + end |
| 60 | + |
| 61 | + # Add framework to target as "Embedded Frameworks" |
| 62 | + |
| 63 | + build_file = embed_frameworks_build_phase.add_file_reference(framework_ref) |
| 64 | + target.frameworks_build_phase.add_file_reference(framework_ref) |
| 65 | + build_file.settings = { 'ATTRIBUTES' => ['CodeSignOnCopy', 'RemoveHeadersOnCopy'] } |
| 66 | + |
| 67 | + |
| 68 | + #Add New Run Script Phase to Build Phases |
| 69 | + phase = target.new_shell_script_build_phase(INSTABUG_PHASE_NAME) |
| 70 | + phase.shell_script = INSTABUG_PHASE_SCRIPT |
| 71 | + end |
| 72 | +end |
60 | 73 |
|
61 | 74 | # Save Xcode project
|
62 | 75 | project.save
|
0 commit comments