Skip to content

Commit 1d6fdb1

Browse files
committed
🚑 Add preunlink script to remove Instabug.framework from the project.
1 parent 720581c commit 1d6fdb1

File tree

3 files changed

+57
-3
lines changed

3 files changed

+57
-3
lines changed

link.rb

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,15 @@
3838

3939
# Add framework search path to target
4040
['Debug', 'Release'].each do |config|
41-
paths = ['$(inherited)', framework_root]
42-
target.build_settings(config)['FRAMEWORK_SEARCH_PATHS'] = paths
41+
paths = ['$(inherited', framework_root]
42+
if target.build_settings(config)['FRAMEWORK_SEARCH_PATHS'] == nil
43+
target.build_settings(config)['FRAMEWORK_SEARCH_PATHS'] = paths
44+
elsif target.build_settings(config)['FRAMEWORK_SEARCH_PATHS'].kind_of?(Array)
45+
target.build_settings(config)['FRAMEWORK_SEARCH_PATHS'] << framework_root unless target.build_settings(config)['FRAMEWORK_SEARCH_PATHS'].include? framework_root
46+
else
47+
paths = [target.build_settings(config)['FRAMEWORK_SEARCH_PATHS'], framework_root]
48+
target.build_settings(config)['FRAMEWORK_SEARCH_PATHS'] = paths
49+
end
4350
end
4451

4552
# Add framework to target as "Embedded Frameworks"

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@
2323
"homepage": "https://github.com/Instabug/instabug-reactnative#readme",
2424
"rnpm": {
2525
"commands": {
26-
"postlink": "ruby ./node_modules/instabug-reactnative/link.rb || echo \"Ruby doesn't exist, if you're building this for Android only, then feel free to ignore this error, otherwise please install Ruby and run 'react-native link instabug-reactnative' again\""
26+
"postlink": "ruby ./node_modules/instabug-reactnative/link.rb || echo \"Ruby doesn't exist, if you're building this for Android only, then feel free to ignore this error, otherwise please install Ruby and run 'react-native link instabug-reactnative' again\"",
27+
"preunlink": "ruby ./node_modules/instabug-reactnative/unlink.rb || echo \"Ruby doesn't exist, if you're building this for Android only, then feel free to ignore this error, otherwise please install Ruby and run 'react-native link instabug-reactnative' again\""
2728
},
2829
"android": {
2930
"packageInstance": "\t\tnew RNInstabugReactnativePackage.Builder(\"YOUR_ANDROID_APPLICATION_TOKEN\",MainApplication.this)\n\t\t\t\t\t\t\t.setInvocationEvent(\"shake\")\n\t\t\t\t\t\t\t.setPrimaryColor(\"#1D82DC\")\n\t\t\t\t\t\t\t.setFloatingEdge(\"left\")\n\t\t\t\t\t\t\t.setFloatingButtonOffsetFromTop(250)\n\t\t\t\t\t\t\t.build()"

unlink.rb

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#!/usr/bin/env ruby
2+
begin
3+
require 'xcodeproj'
4+
rescue LoadError
5+
puts('xcodeproj doesn\'t exist')
6+
Kernel.exit(0)
7+
end
8+
require 'fileutils'
9+
10+
# Replace these with your values
11+
current_path = Dir.pwd
12+
project_path = Dir.glob("#{current_path}/ios/*.xcodeproj").first
13+
file_name = File.basename(project_path, ".xcodeproj")
14+
project_location = './ios/'+file_name+'.xcodeproj'
15+
target_name = file_name
16+
framework_root = '../node_modules/instabug-reactnative/ios'
17+
framework_name = 'Instabug.framework'
18+
19+
INSTABUG_PHASE_NAME = "Strip Frameworks"
20+
21+
# Get useful variables
22+
project = Xcodeproj::Project.open(project_location)
23+
frameworks_group = project.groups.find { |group| group.display_name == 'Frameworks' }
24+
target = project.targets.find { |target| target.to_s == target_name }
25+
frameworks_build_phase = target.build_phases.find { |build_phase| build_phase.to_s == 'FrameworksBuildPhase' }
26+
27+
# Remove "Embed Frameworks" build phase to target
28+
embed_frameworks_build_phase = target.build_phases.find { |build_phase| build_phase.to_s == 'Embed Frameworks'}
29+
target.build_phases.delete(embed_frameworks_build_phase)
30+
31+
# Remove framework search path from target
32+
['Debug', 'Release'].each do |config|
33+
target.build_settings(config)['FRAMEWORK_SEARCH_PATHS'].delete(framework_root)
34+
end
35+
36+
# Remove framework from target from "Embedded Frameworks"
37+
framework_ref = frameworks_group.files.find { |file_reference| file_reference.path == "#{framework_root}/#{framework_name}"}
38+
frameworks_build_phase.remove_file_reference(framework_ref)
39+
framework_ref.remove_from_project
40+
41+
#Delete New Run Script Phase from Build Phases
42+
shell_script_build_phase = target.shell_script_build_phases.find { |build_phase| build_phase.to_s == INSTABUG_PHASE_NAME }
43+
target.build_phases.delete(shell_script_build_phase)
44+
45+
# Save Xcode project
46+
project.save

0 commit comments

Comments
 (0)