-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathXcodeTool.rb
167 lines (152 loc) · 6.83 KB
/
XcodeTool.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
# 使用方法:cd到脚本所在目录,终端运行`ruby XcodeTool.rb`
require 'xcodeproj'
# 消除第三方库 deployment target警告,比如这样的:The iOS deployment target 'IPHONEOS_DEPLOYMENT_TARGET' is set to 8.0, but the range of supported deployment target versions is 9.0 to 14.2.99.
# your_target是你的工程Target名字(每个项目都不一样,请按需修改)
# 还可以消除 Command CompileSwiftSources failed with a nonzero exit code 错误
# min_surpport_version是你的项目支持的最低版本
def fix_deployment_target(your_target,min_surpport_version)
project_name = your_target
full_proj_path = Dir.pwd #当前目录,比如/Users/xxx/Documents/Project/iOS/PandaNote
full_proj_path = full_proj_path + "/Pods/*.xcodeproj"
puts full_proj_path
all_file = Dir[full_proj_path]
puts "\n\n\nfix_deployment_target\n如果上面出现Traceback错误(白色加粗字体),请再执行一遍pod install命令\n\n\n"
# puts all_file
all_file.each do |file_name|
# puts "fix:#{file_name}"
project = Xcodeproj::Project.open(file_name)
project.targets.each do |target|
target.build_configurations.each do |config|
# puts target.name
# puts "config.name is #{config.name}"
if config.name == 'Release'
if config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'].to_f < min_surpport_version.to_f
config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = min_surpport_version
end
end
if config.name == 'Debug'
if config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'].to_f < min_surpport_version.to_f
config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = min_surpport_version
end
end
end
end
project.save
end
puts "fix deployment target finished 已设置工程支持的最低版本为#{min_surpport_version.to_s}"
end
# https://stackoverflow.com/questions/63614048/xcode-12-sessiondelegate-has-different-definitions-in-different-modules
# 解决问题:'SessionDelegate' has different definitions in different modules; first difference is definition in module 'Alamofire.Swift' found 0 referenced protocols
def fix_has_different_definitions_in_different_modules(your_target)
project_name = your_target
full_proj_path = Dir.pwd #当前目录,比如/Users/xxx/Documents/Project/iOS/PandaNote
full_proj_path = full_proj_path + "/Pods/*.xcodeproj"
puts full_proj_path
all_file = Dir[full_proj_path]
all_file.each do |file_name|
project = Xcodeproj::Project.open(file_name)
project.targets.each do |target|
target.build_configurations.each do |config|
if target.name == 'Alamofire'
target.build_configurations.each do |config|
config.build_settings['SWIFT_INSTALL_OBJC_HEADER'] = 'NO'
end
end
end
end
project.save
end
puts "fix error: 'SessionDelegate' has different definitions in different modules; first difference is definition in module 'Alamofire.Swift' found 0 referenced protocols"
end
# 禁止该死的Documentation Issue
def disableDocumentationIssue(your_target,isAllPods)
puts isAllPods.class
project_name = your_target
full_proj_path = Dir.pwd #当前目录,比如/Users/xxx/Documents/Project/iOS/PandaNote
if isAllPods
full_proj_path = full_proj_path + "/Pods/*.xcodeproj"
else
full_proj_path = full_proj_path + "/Pods/Pods.xcodeproj"
end
puts full_proj_path
all_file = Dir[full_proj_path]
all_file.each do |file_name|
puts file_name
project = Xcodeproj::Project.open(file_name)
project.targets.each do |target|
puts "==="
puts target.inspect
target.build_configurations.each do |config|
config.build_settings['CLANG_WARN_DOCUMENTATION_COMMENTS'] = 'NO'
end
end
project.save
end
end
# 方式是先修改众多警告的一个,然后修改一个警告,看看sourceTree里面的`project.pbxproj`文件到底是哪一行有改动,然后用我这个脚本用到的xcodeproj工具修改
# 消除Update to recommended settings警告 isAllPods是true的话修改所有工程(Podfile设置了generate_multiple_pod_projects: true的话)
# LastUpgradeVersion是此文件里面的值(PandaNote是我的工程名):PandaNote.xcodeproj/xcshareddata/xcschemes/PandaNote.xcscheme
def disableRecommendedIssue(your_target,isAllPods,lastUpgradeVersion)
puts isAllPods.class
project_name = your_target
full_proj_path = Dir.pwd #当前目录,比如/Users/xxx/Documents/Project/iOS/PandaNote
if isAllPods
full_proj_path = full_proj_path + "/Pods/*.xcodeproj"
else
full_proj_path = full_proj_path + "/Pods/Pods.xcodeproj"#单个工程
end
puts full_proj_path
all_file = Dir[full_proj_path]
all_file.each do |file_name|
puts "开始修改"
puts file_name
project = Xcodeproj::Project.open(file_name)
#真不容易啊,在这个地方搜“PBXProject”才知道是root_object https://www.rubydoc.info/gems/xcodeproj/Xcodeproj/Project
puts project.root_object.attributes.inspect
# number = project.root_object.attributes["LastUpgradeCheck"].to_i#Integer("123")也行
# number = number + 10
# numberStr = number.to_s
# nnn = Integer("123")
# puts numberStr
project.root_object.attributes["LastUpgradeCheck"] = lastUpgradeVersion
project.save
end
end
# 下面一行解注释会消除Update to recommended settings警告
# disableRecommendedIssue("PandaNote",true,"1230")
# fix_deployment_target("PandaNote","10.0")
def testfunc(version)
puts "this is a test function:#{version}"
end
def handleCommand(command,param)
if command == "fix_deployment_target"
fix_deployment_target("PandaNote",param)
elsif command == "fix_has_different_definitions_in_different_modules"
fix_has_different_definitions_in_different_modules(param)
else
puts "sorry your command is not found"
end
end
# 命令行的参数
v1 = ARGV[0]
v2 = ARGV[1]
order_name = -1
if v1.instance_of? String
handleCommand(v1,v2)
else
puts "你想要我做什么? Please enter your command:\n
1.消除第三方库 deployment target警告 fix_deployment_target
2.testfunc"
# 等待用户输入
order_name = gets
# 指令转换成整数
order_num = order_name.to_i(base=10)
if order_num == 1
puts "input min deployment target version:"
v2 = gets
v2 = v2.to_i()
fix_deployment_target(param)
elsif order_num == 2
testfunc(v2)
end
end