-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathandroid
256 lines (199 loc) · 6.12 KB
/
android
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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
def gradle_archive (options)
build_type = 'Debug'
task = 'assemble'
is_bundle = false
if (options[:env] === 'staging' || options[:env] === 'prod')
build_type = 'Release'
task = 'bundle'
is_bundle = true
if (options[:build_apk])
task = 'assemble'
is_bundle = false
end
end
file = options[:keystore_file] ? options[:keystore_file] : ENV['KEYSTORE_FILE']
password = options[:keystore_password] ? options[:keystore_password] : ENV['KEYSTORE_PASSWORD']
keystore_alias = options[:keystore_alias] ? options[:keystore_alias] : ENV['KEYSTORE_ALIAS']
passphrase = options[:passphrase] ? options[:passphrase] : ENV['KEYSTORE_PASSPHRARE']
system_properties = lane_context[:GRADLE_SYSTEM_PROPERTIES] ? lane_context[:GRADLE_SYSTEM_PROPERTIES] : {}
if (password and keystore_alias and passphrase)
credentials = {
'KEYSTORE_FILE' => file,
'KEYSTORE_PASSWORD' => password,
'KEYSTORE_ALIAS' => keystore_alias,
'KEYSTORE_PASSPHRARE' => passphrase
}
system_properties.merge!(credentials)
end
project_dir = options[:project_dir] ? options[:project_dir] : '.'
if (options[:clean])
gradle(task: 'clean', project_dir: project_dir)
end
properties = lane_context[:GRADLE_PROPERTIES] ? lane_context[:GRADLE_PROPERTIES] : {}
flavor = lane_context[:GRADLE_FLAVOR] ? lane_context[:GRADLE_FLAVOR] : ENV['GRADLE_FLAVOR']
flavor = options[:flavor] ? options[:flavor] : flavor
gradle(
task: task,
build_type: build_type,
project_dir: project_dir,
properties: properties,
flavor: flavor,
system_properties: system_properties
)
path_build_type = build_type.downcase
basename = "app-#{path_build_type}"
folder_type = "apk"
extension = "apk"
if (is_bundle)
folder_type = "bundle"
extension = "aab"
end
folder = "#{folder_type}/#{path_build_type}"
if (flavor)
flavor_downcase = flavor.downcase
if (is_bundle)
folder = "#{folder_type}/#{flavor_downcase}#{path_build_type.capitalize()}"
basename = "app"
else
folder = "#{folder_type}/#{flavor_downcase}/#{path_build_type}"
basename = "app-#{flavor_downcase}-#{path_build_type}"
end
end
binary_file = "./android/app/build/outputs/#{folder}/#{basename}.#{extension}"
lane_context[:SUPPLY_OPTIONS][extension] = binary_file
Dir.chdir ".." do
FileUtils.mkdir_p output_path()
FileUtils.cp(binary_file, output_path())
end
end
platform :android do
private_lane :generate_json_key do
if (ENV.key?('SUPPLY_JSON_KEY'))
json_key = gpg_decrypt( file: ENV['SUPPLY_JSON_KEY'], passphrase: ENV['GPG_PASSPHRASE'] )
end
end
private_lane :store do |options|
json_key = generate_json_key
unless json_key
UI.user_error!("Generate json_key.")
end
defaultOptions = {
package_name: ENV['APP_IDENTIFIER'],
track: options[:track] ? options[:track] : 'alpha',
json_key: json_key,
skip_upload_metadata: true,
skip_upload_images: true,
skip_upload_screenshots: true
}
supply_options = lane_context[:SUPPLY_OPTIONS] ? lane_context[:SUPPLY_OPTIONS] : {}
upload_to_play_store(defaultOptions.merge!(supply_options))
end
lane :android_archive do |options|
gradle_archive(options)
end
lane :generate_jks do
output = ''
if (ENV.key?('KEYSTORE_FILE'))
output = gpg_decrypt( file: ENV['KEYSTORE_FILE'], passphrase: ENV['GPG_PASSPHRASE'] )
end
end
lane :generate_google_services do
# todo check file exists
if (ENV.key?('GOOGLE_SERVICES_JSON'))
gpg_decrypt( file: ENV['GOOGLE_SERVICES_JSON'], passphrase: ENV['GPG_PASSPHRASE'] )
end
end
lane :version do |options|
properties = lane_context[:GRADLE_PROPERTIES] ? lane_context[:GRADLE_PROPERTIES] : {}
version = options[:version] ? options[:version] : ENV['APP_VERSION']
unless version.nil?
properties[:versionName] = options[:version]
end
unless options[:build_number].nil?
properties[:versionCode] = options[:build_number]
end
lane_context[:GRADLE_PROPERTIES] = properties
options
end
lane :prepare do |options|
lane_context[:SUPPLY_OPTIONS] = {}
requirements(options)
generate_google_services
options[:keystore_file] = generate_jks
# after prepare
after_android_prepare(options)
end
lane :build do |options|
# prepare generate google services check install
prepare(options)
begin
android_archive_override(options)
rescue
android_archive(options)
end
bitrise_env('BITRISE_DEPLOY_DIR', output_path())
# after build
after_android_build(options)
end
lane :dev do |options|
ENV['LANE_ENV'] = 'dev'
options[:env] = 'dev'
before_android_dev(options)
options = version(options)
build(options)
after_android_dev(options)
end
lane :staging do |options|
ENV['LANE_ENV'] = 'staging'
options[:env] = 'staging'
before_android_staging(options)
version(options)
unless options[:skip_build]
build(options)
end
unless options[:skip_store]
store(options)
end
after_android_staging(options)
end
lane :prod do |options|
ENV['LANE_ENV'] = 'prod'
options[:env] = 'prod'
unless options[:track]
options[:track] = 'beta'
end
before_android_prod(options)
version(options)
unless options[:skip_build]
build(options)
end
unless options[:skip_store]
store(options)
end
after_android_prod(options)
end
end
lane :after_android_prepare do |options|
UI.success "hook after_android_prepare"
end
lane :after_android_build do |options|
UI.success "hook after_android_builds"
end
lane :after_android_dev do |options|
UI.success "hook after_android_dev"
end
lane :after_android_staging do |options|
UI.success "hook after_android_staging"
end
lane :after_android_prod do |options|
UI.success "hook after_android_prod"
end
lane :before_android_dev do |options|
UI.success "hook before_android_dev"
end
lane :before_android_staging do |options|
UI.success "hook before_android_staging"
end
lane :before_android_prod do |options|
UI.success "hook before_android_prod"
end