@@ -26,7 +26,7 @@ def self.run(params)
26
26
# Add device-specific 'splits' metrics to the payload if a `:include_split_sizes` is enabled
27
27
if params [ :include_split_sizes ]
28
28
check_bundletool_installed!
29
- apkanalyzer_bin = find_apkanalyzer_binary!
29
+ apkanalyzer_bin = params [ :apkanalyzer_binary ] || find_apkanalyzer_binary!
30
30
UI . message ( "[App Size Metrics] Generating the various APK splits from #{ params [ :aab_path ] } ..." )
31
31
Dir . mktmpdir ( 'release-toolkit-android-app-size-metrics' ) do |tmp_dir |
32
32
Action . sh ( 'bundletool' , 'build-apks' , '--bundle' , params [ :aab_path ] , '--output-format' , 'DIRECTORY' , '--output' , tmp_dir )
@@ -61,10 +61,18 @@ def self.check_bundletool_installed!
61
61
raise
62
62
end
63
63
64
- def self . find_apkanalyzer_binary!
64
+ def self . find_apkanalyzer_binary
65
65
sdk_root = ENV [ 'ANDROID_SDK_ROOT' ] || ENV [ 'ANDROID_HOME' ]
66
- apkanalyzer_bin = sdk_root . nil? ? Action . sh ( 'command' , '-v' , 'apkanalyzer' ) : File . join ( sdk_root , 'cmdline-tools' , 'latest' , 'bin' , 'apkanalyzer' )
67
- UI . user_error! ( 'Unable to find apkanalyzer executable. Make sure you installed the Android SDK Command-line Tools' ) unless File . executable? ( apkanalyzer_bin )
66
+ if sdk_root
67
+ pattern = File . join ( sdk_root , 'cmdline-tools' , '{latest,tools}' , 'bin' , 'apkanalyzer' )
68
+ apkanalyzer_bin = Dir . glob ( pattern ) . find { |path | File . executable? ( path ) }
69
+ end
70
+ apkanalyzer_bin || Action . sh ( 'command' , '-v' , 'apkanalyzer' , print_command_output : false ) { |_ | nil }
71
+ end
72
+
73
+ def self . find_apkanalyzer_binary!
74
+ apkanalyzer_bin = find_apkanalyzer_binary
75
+ UI . user_error! ( 'Unable to find `apkanalyzer` executable in `$PATH` nor `$ANDROID_SDK_ROOT`. Make sure you installed the Android SDK Command-line Tools' ) if apkanalyzer_bin . nil?
68
76
apkanalyzer_bin
69
77
end
70
78
@@ -170,6 +178,17 @@ def self.available_options
170
178
type : FastlaneCore ::Boolean ,
171
179
default_value : true
172
180
) ,
181
+ FastlaneCore ::ConfigItem . new (
182
+ key : :apkanalyzer_binary ,
183
+ env_name : 'FL_ANDROID_SEND_APP_SIZE_METRICS_APKANALYZER_BINARY' ,
184
+ description : 'The path to the `apkanalyzer` binary to use. If not provided explicitly, we will use `$PATH` and `$ANDROID_SDK_HOME` to try to find it' ,
185
+ type : String ,
186
+ default_value : find_apkanalyzer_binary ,
187
+ default_value_dynamic : true ,
188
+ verify_block : proc do |value |
189
+ UI . user_error! ( 'You must provide a path to an existing executable for `apkanalyzer`' ) unless File . executable? ( value )
190
+ end
191
+ ) ,
173
192
]
174
193
end
175
194
0 commit comments