Skip to content

Commit af79c8d

Browse files
committed
增加ios 构建脚本
1 parent 82425f8 commit af79c8d

File tree

6 files changed

+239
-4
lines changed

6 files changed

+239
-4
lines changed

example/ios/Runner.xcodeproj/project.pbxproj

+5
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464
B1DCC12D5C37AABB2D7D9977 /* Pods-Runner.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Runner.debug.xcconfig"; path = "Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig"; sourceTree = "<group>"; };
6565
B48C97BE82EEE1FF75F13BB7 /* Pods_Runner.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_Runner.framework; sourceTree = BUILT_PRODUCTS_DIR; };
6666
B845790FCC1D6451F282EB5C /* Pods-RunnerTests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-RunnerTests.debug.xcconfig"; path = "Target Support Files/Pods-RunnerTests/Pods-RunnerTests.debug.xcconfig"; sourceTree = "<group>"; };
67+
D1B9C7820E29835E00891644 /* Runner.entitlements */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.plist.entitlements; path = Runner.entitlements; sourceTree = "<group>"; };
6768
E5054B799B78E018D56EC024 /* Pods-Runner.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Runner.release.xcconfig"; path = "Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig"; sourceTree = "<group>"; };
6869
/* End PBXFileReference section */
6970

@@ -161,6 +162,7 @@
161162
1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */,
162163
74858FAE1ED2DC5600515810 /* AppDelegate.swift */,
163164
74858FAD1ED2DC5600515810 /* Runner-Bridging-Header.h */,
165+
D1B9C7820E29835E00891644 /* Runner.entitlements */,
164166
);
165167
path = Runner;
166168
sourceTree = "<group>";
@@ -468,6 +470,7 @@
468470
buildSettings = {
469471
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
470472
CLANG_ENABLE_MODULES = YES;
473+
CODE_SIGN_ENTITLEMENTS = Runner/Runner.entitlements;
471474
CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)";
472475
DEVELOPMENT_TEAM = TJ43D84A6Q;
473476
ENABLE_BITCODE = NO;
@@ -647,6 +650,7 @@
647650
buildSettings = {
648651
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
649652
CLANG_ENABLE_MODULES = YES;
653+
CODE_SIGN_ENTITLEMENTS = Runner/Runner.entitlements;
650654
CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)";
651655
DEVELOPMENT_TEAM = TJ43D84A6Q;
652656
ENABLE_BITCODE = NO;
@@ -670,6 +674,7 @@
670674
buildSettings = {
671675
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
672676
CLANG_ENABLE_MODULES = YES;
677+
CODE_SIGN_ENTITLEMENTS = Runner/Runner.entitlements;
673678
CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)";
674679
DEVELOPMENT_TEAM = TJ43D84A6Q;
675680
ENABLE_BITCODE = NO;

example/ios/Runner/Info.plist

+31-4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
33
<plist version="1.0">
44
<dict>
5+
<key>CADisableMinimumFrameDurationOnPhone</key>
6+
<true/>
57
<key>CFBundleDevelopmentRegion</key>
68
<string>$(DEVELOPMENT_LANGUAGE)</string>
79
<key>CFBundleDisplayName</key>
@@ -20,10 +22,39 @@
2022
<string>$(FLUTTER_BUILD_NAME)</string>
2123
<key>CFBundleSignature</key>
2224
<string>????</string>
25+
<key>CFBundleURLTypes</key>
26+
<array>
27+
<dict>
28+
<key>CFBundleTypeRole</key>
29+
<string>Editor</string>
30+
<key>CFBundleURLName</key>
31+
<string>douyin</string>
32+
<key>CFBundleURLSchemes</key>
33+
<array>
34+
<string>123456</string>
35+
</array>
36+
</dict>
37+
</array>
2338
<key>CFBundleVersion</key>
2439
<string>$(FLUTTER_BUILD_NUMBER)</string>
40+
<key>LSApplicationQueriesSchemes</key>
41+
<array>
42+
<string>douyinopensdk</string>
43+
<string>douyinliteopensdk</string>
44+
<string>douyinsharesdk</string>
45+
<string>snssdk1128</string>
46+
</array>
2547
<key>LSRequiresIPhoneOS</key>
2648
<true/>
49+
<key>NSAppTransportSecurity</key>
50+
<dict>
51+
<key>NSAllowsArbitraryLoads</key>
52+
<true/>
53+
<key>NSAllowsArbitraryLoadsInWebContent</key>
54+
<true/>
55+
</dict>
56+
<key>UIApplicationSupportsIndirectInputEvents</key>
57+
<true/>
2758
<key>UILaunchStoryboardName</key>
2859
<string>LaunchScreen</string>
2960
<key>UIMainStoryboardFile</key>
@@ -41,9 +72,5 @@
4172
<string>UIInterfaceOrientationLandscapeLeft</string>
4273
<string>UIInterfaceOrientationLandscapeRight</string>
4374
</array>
44-
<key>CADisableMinimumFrameDurationOnPhone</key>
45-
<true/>
46-
<key>UIApplicationSupportsIndirectInputEvents</key>
47-
<true/>
4875
</dict>
4976
</plist>
+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict/>
5+
</plist>

example/pubspec.yaml

+3
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ dev_dependencies:
4242
# rules and activating additional ones.
4343
flutter_lints: ^2.0.0
4444

45+
fludy:
46+
client_key: 123456
47+
4548
# For information on the generic Dart part of this file, see the
4649
# following page: https://dart.dev/tools/pub/pubspec
4750

ios/douyin_setup.rb

+158
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
#
2+
# Reference documentations
3+
# https://github.com/firebase/flutterfire/blob/master/packages/firebase_crashlytics/firebase_crashlytics/ios/crashlytics_add_upload_symbols
4+
# https://github.com/MagicalWater/Base-APP-Env/blob/master/fastlane/actions/xcode_parse.rb
5+
#
6+
7+
require 'xcodeproj'
8+
require 'plist'
9+
require 'optparse'
10+
require 'uri'
11+
12+
# Dictionary to hold command line arguments
13+
options_dict = {}
14+
15+
# Parse command line arguments into options_dict
16+
OptionParser.new do |options|
17+
options.banner = "Setup the Wechat to an Xcode target."
18+
19+
options.on("-p", "--projectDirectory=DIRECTORY", String, "Directory of the Xcode project") do |dir|
20+
options_dict[:project_dir] = dir
21+
end
22+
23+
options.on("-n", "--projectName=NAME", String, "Name of the Xcode project (ex: Runner.xcodeproj)") do |name|
24+
options_dict[:project_name] = name
25+
end
26+
27+
options.on("-i", "--ignoreSecurity", "Ignore modifying NSAppTransportSecurity") do |opts|
28+
options_dict[:ignore_security] = true
29+
end
30+
31+
options.on("-a", "--appId=APPID", String, "App ID for Wechat") do |opts|
32+
options_dict[:app_id] = opts
33+
end
34+
35+
options.on("-u", "--universalLink=UNIVERSALLINK", String, "Universal Link for Wechat") do |opts|
36+
options_dict[:universal_link] = opts
37+
end
38+
end.parse!
39+
40+
# Minimum required arguments are a project directory and project name
41+
unless (options_dict[:project_dir] and options_dict[:project_name])
42+
abort("Must provide a project directory and project name.\n")
43+
end
44+
45+
# Path to the Xcode project to modify
46+
project_path = File.join(options_dict[:project_dir], options_dict[:project_name])
47+
48+
unless (File.exist?(project_path))
49+
abort("Project at #{project_path} does not exist. Please check paths manually.\n");
50+
end
51+
52+
# Actually open and modify the project
53+
project = Xcodeproj::Project.open(project_path)
54+
project.targets.each do |target|
55+
if target.name == "Runner"
56+
app_id = options_dict[:app_id]
57+
58+
sectionObject = {}
59+
project.objects.each do |object|
60+
if object.uuid == target.uuid
61+
sectionObject = object
62+
break
63+
end
64+
end
65+
sectionObject.build_configurations.each do |config|
66+
infoplist = config.build_settings["INFOPLIST_FILE"]
67+
if !infoplist
68+
abort("INFOPLIST_FILE is not exist\n")
69+
end
70+
infoplistFile = File.join(options_dict[:project_dir], infoplist)
71+
if !File.exist?(infoplistFile)
72+
abort("#{infoplist} is not exist\n")
73+
end
74+
result = Plist.parse_xml(infoplistFile, marshal: false)
75+
if !result
76+
result = {}
77+
end
78+
urlTypes = result["CFBundleURLTypes"]
79+
if !urlTypes
80+
urlTypes = []
81+
result["CFBundleURLTypes"] = urlTypes
82+
end
83+
isUrlTypeExist = urlTypes.any? { |urlType| urlType["CFBundleURLSchemes"] && (urlType["CFBundleURLSchemes"].include? app_id) }
84+
if !app_id.nil? && !app_id.empty? && !isUrlTypeExist
85+
print("writing app id\n ")
86+
urlTypes << {
87+
"CFBundleTypeRole": "Editor",
88+
"CFBundleURLName": "douyin",
89+
"CFBundleURLSchemes": [ app_id ]
90+
}
91+
File.write(infoplistFile, Plist::Emit.dump(result))
92+
end
93+
94+
queriesSchemes = result["LSApplicationQueriesSchemes"]
95+
if !queriesSchemes
96+
queriesSchemes = []
97+
result["LSApplicationQueriesSchemes"] = queriesSchemes
98+
end
99+
douYinQueriesSchemes = ["douyinopensdk", "douyinliteopensdk", "douyinsharesdk", "snssdk1128"]
100+
if douYinQueriesSchemes.any? { |queriesScheme| !(queriesSchemes.include? queriesScheme) }
101+
douYinQueriesSchemes.each do |queriesScheme|
102+
if !(queriesSchemes.include? queriesScheme)
103+
queriesSchemes << queriesScheme
104+
end
105+
end
106+
File.write(infoplistFile, Plist::Emit.dump(result))
107+
end
108+
if !options_dict[:ignore_security]
109+
security = result["NSAppTransportSecurity"]
110+
if !security
111+
security = {}
112+
result["NSAppTransportSecurity"] = security
113+
end
114+
if security["NSAllowsArbitraryLoads"] != true
115+
security["NSAllowsArbitraryLoads"] = true
116+
File.write(infoplistFile, Plist::Emit.dump(result))
117+
end
118+
if security["NSAllowsArbitraryLoadsInWebContent"] != true
119+
security["NSAllowsArbitraryLoadsInWebContent"] = true
120+
File.write(infoplistFile, Plist::Emit.dump(result))
121+
end
122+
end
123+
end
124+
sectionObject.build_configurations.each do |config|
125+
codeSignEntitlements = config.build_settings["CODE_SIGN_ENTITLEMENTS"]
126+
if !codeSignEntitlements
127+
codeSignEntitlements = "Runner/Runner.entitlements"
128+
config.build_settings["CODE_SIGN_ENTITLEMENTS"] = codeSignEntitlements
129+
project.save()
130+
end
131+
codeSignEntitlementsFile = File.join(options_dict[:project_dir], codeSignEntitlements)
132+
if !File.exist?(codeSignEntitlementsFile)
133+
content = Plist::Emit.dump({})
134+
File.write(codeSignEntitlementsFile, content)
135+
end
136+
runnerTargetMainGroup = project.main_group.find_subpath('Runner', false)
137+
isRefExist = runnerTargetMainGroup.files.any? { |file| file.path.include? File.basename(codeSignEntitlementsFile) }
138+
if !isRefExist
139+
runnerTargetMainGroup.new_reference(File.basename(codeSignEntitlementsFile))
140+
project.save()
141+
end
142+
result = Plist.parse_xml(codeSignEntitlementsFile, marshal: false)
143+
if !result
144+
result = {}
145+
end
146+
domains = result["com.apple.developer.associated-domains"]
147+
if !domains
148+
domains = []
149+
result["com.apple.developer.associated-domains"] = domains
150+
end
151+
# isApplinksExist = domains.include? applinks
152+
# if !isApplinksExist
153+
# domains << applinks
154+
# File.write(codeSignEntitlementsFile, Plist::Emit.dump(result))
155+
# end
156+
end
157+
end
158+
end

ios/fludy.podspec

+37
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,43 @@
22
# To learn more about a Podspec see http://guides.cocoapods.org/syntax/podspec.html.
33
# Run `pod lib lint fludy.podspec` to validate before publishing.
44
#
5+
pubspec = YAML.load_file(File.join('..', 'pubspec.yaml'))
6+
library_version = pubspec['version'].gsub('+', '-')
7+
8+
current_dir = Dir.pwd
9+
calling_dir = File.dirname(__FILE__)
10+
project_dir = calling_dir.slice(0..(calling_dir.index('/.symlinks')))
11+
symlinks_index = calling_dir.index('/ios/.symlinks')
12+
if !symlinks_index
13+
symlinks_index = calling_dir.index('/.ios/.symlinks')
14+
end
15+
16+
flutter_project_dir = calling_dir.slice(0..(symlinks_index))
17+
18+
puts Psych::VERSION
19+
psych_version_gte_500 = Gem::Version.new(Psych::VERSION) >= Gem::Version.new('5.0.0')
20+
if psych_version_gte_500 == true
21+
cfg = YAML.load_file(File.join(flutter_project_dir, 'pubspec.yaml'), aliases: true)
22+
else
23+
cfg = YAML.load_file(File.join(flutter_project_dir, 'pubspec.yaml'))
24+
end
25+
26+
ignore_security = ''
27+
if cfg['fludy'] && cfg['fludy']['ios'] && cfg['fludy']['ios']['ignore_security'] == true
28+
ignore_security = '-i'
29+
end
30+
Pod::UI.puts "ignore_security: #{ignore_security}"
31+
32+
client_key = ''
33+
34+
if cfg['fludy'] && cfg['fludy']['client_key']
35+
client_key = cfg['fludy']['client_key']
36+
end
37+
38+
39+
Pod::UI.puts "client_key: #{client_key}"
40+
system("ruby #{current_dir}/douyin_setup.rb #{ignore_security} -a #{client_key} -p #{project_dir} -n Runner.xcodeproj")
41+
542
Pod::Spec.new do |s|
643
s.name = 'fludy'
744
s.version = '0.0.1'

0 commit comments

Comments
 (0)