Skip to content

Commit f6e2d48

Browse files
author
Rynaard Burger
committed
Move and rename action to the android namespace
1 parent 5a54afc commit f6e2d48

File tree

2 files changed

+135
-104
lines changed

2 files changed

+135
-104
lines changed
Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
module Fastlane
2+
module Actions
3+
class AndroidGenerateApkFromAabAction < Action
4+
def self.run(params)
5+
begin
6+
sh('command -v bundletool > /dev/null')
7+
rescue StandardError
8+
UI.user_error!('bundletool is not installed. Please install it using the instructions at https://developer.android.com/studio/command-line/bundletool.')
9+
raise
10+
end
11+
12+
# If no AAB param was provided, attempt to get it from the lane context
13+
# First GRADLE_ALL_AAB_OUTPUT_PATHS if only one
14+
# Second GRADLE_AAB_OUTPUT_PATH if it is set
15+
# Else use the specified parameter value
16+
if params[:aab_file_path].nil?
17+
all_aab_paths = Actions.lane_context[SharedValues::GRADLE_ALL_AAB_OUTPUT_PATHS] || []
18+
aab_file_path = if all_aab_paths.count == 1
19+
all_aab_paths.first
20+
else
21+
Actions.lane_context[SharedValues::GRADLE_AAB_OUTPUT_PATH]
22+
end
23+
else
24+
aab_file_path = params[:aab_file_path]
25+
end
26+
27+
apk_output_file_path = params[:apk_output_file_path]
28+
keystore_path = params[:keystore_path]
29+
keystore_password = params[:keystore_password]
30+
keystore_key_alias = params[:keystore_key_alias]
31+
signing_key_password = params[:signing_key_password]
32+
33+
# Generate an unsigned APK if no keystore_path parameter is specified
34+
# Else generate a signed APK
35+
if keystore_path.nil?
36+
sh('bundletool', 'build-apks',
37+
'--mode', 'universal',
38+
'--bundle', aab_file_path,
39+
'--output-format', 'DIRECTORY',
40+
'--output', apk_output_file_path,
41+
'&&', 'mv', "#{apk_output_file_path}/universal.apk", apk_output_file_path,
42+
'&&', 'rm', '-rf', apk_output_file_path)
43+
else
44+
sh('bundletool', 'build-apks',
45+
'--mode', 'universal',
46+
'--bundle', aab_file_path,
47+
'--output-format', 'DIRECTORY',
48+
'--output', apk_output_file_path,
49+
'--ks', keystore_path,
50+
'--ks-pass', keystore_password,
51+
'--ks-key-alias', keystore_key_alias,
52+
'--key-pass', signing_key_password,
53+
'&&', 'mv', "#{apk_output_file_path}/universal.apk", apk_output_file_path,
54+
'&&', 'rm', '-rf', apk_output_file_path)
55+
end
56+
end
57+
58+
#####################################################
59+
# @!group Documentation
60+
#####################################################
61+
62+
def self.description
63+
'Generates an APK from the specified AAB'
64+
end
65+
66+
def self.details
67+
'Generates an APK from the specified AAB'
68+
end
69+
70+
def self.available_options
71+
[
72+
FastlaneCore::ConfigItem.new(
73+
key: :aab_file_path,
74+
env_name: 'ANDROID_AAB_FILE_PATH',
75+
description: 'The path to the AAB file. If not speicified, the action will attempt to read from the lane context using the `SharedValues::GRADLE_ALL_AAB_OUTPUT_PATHS` and `SharedValues::GRADLE_AAB_OUTPUT_PATH` keys',
76+
type: String,
77+
optional: true,
78+
default_value: nil,
79+
verify_block: proc { |p| UI.user_error!("AAB path `#{p}` is not a valid file path.") unless File.file?(p) }
80+
),
81+
FastlaneCore::ConfigItem.new(
82+
key: :apk_output_file_path,
83+
env_name: 'ANDROID_APK_OUTPUT_PATH',
84+
description: 'The output path where the APK file will be generated',
85+
type: String,
86+
optional: false,
87+
default_value: nil,
88+
verify_block: proc { |p| UI.user_error!("APK output path `#{p}` is not a valid file path.") unless File.file?(p) }
89+
),
90+
FastlaneCore::ConfigItem.new(
91+
key: :keystore_path,
92+
env_name: 'ANDROID_KEYSTORE_PATH',
93+
description: 'The path to the keystore file',
94+
type: String,
95+
optional: true,
96+
default_value: nil,
97+
verify_block: proc { |p| UI.user_error!("Keystore file path `#{p}` is not a valid file path.") unless File.file?(p) || p.nil }
98+
),
99+
FastlaneCore::ConfigItem.new(
100+
key: :keystore_password,
101+
env_name: 'ANDROID_KEYSTORE_PASSWORD',
102+
description: 'The password for the keystore',
103+
type: String,
104+
optional: true,
105+
default_value: nil
106+
),
107+
FastlaneCore::ConfigItem.new(
108+
key: :keystore_key_alias,
109+
env_name: 'ANDROID_KEYSTORE_KEY_ALIAS',
110+
description: 'The alias of the key in the keystore',
111+
type: String,
112+
optional: true,
113+
default_value: nil
114+
),
115+
FastlaneCore::ConfigItem.new(
116+
key: :signing_key_password,
117+
env_name: 'ANDROID_SIGNING_KEY_PASSWORD',
118+
description: 'The password for the signing key',
119+
type: String,
120+
optional: true,
121+
default_value: nil
122+
),
123+
]
124+
end
125+
126+
def self.authors
127+
['Automattic']
128+
end
129+
130+
def self.is_supported?(platform)
131+
true
132+
end
133+
end
134+
end
135+
end

lib/fastlane/plugin/wpmreleasetoolkit/actions/bundletool/bundletool_generate_universal_signed_apk_action.rb

Lines changed: 0 additions & 104 deletions
This file was deleted.

0 commit comments

Comments
 (0)