Added the functionality to create .aab file along with .apk file (#5884)

* Added the functionality to create .aab file along with .apk file

* Added the logic to decide the type of Android build based on env var
Added .aab in .gitignore file
Added env var in the env_vars_example file

* Review fixes: Changed the name and type of env var along with some refactoring

* Update fastlane/env_vars_example

Co-authored-by: Carrie Warner (Mattermost) <74422101+cwarnermm@users.noreply.github.com>

Co-authored-by: Carrie Warner (Mattermost) <74422101+cwarnermm@users.noreply.github.com>
This commit is contained in:
Manoj Malik 2022-02-01 17:20:53 +05:30 committed by GitHub
parent abe2cefb61
commit 62258b5d64
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 66 additions and 37 deletions

1
.gitignore vendored
View file

@ -30,6 +30,7 @@ DerivedData
*.hmap
*.ipa
*.apk
*.aab
*.xcuserstate
project.xcworkspace
ios/Pods

View file

@ -180,14 +180,16 @@ end
desc 'Upload file to s3'
lane :upload_file_to_s3 do |options|
os_type = options[:os_type].downcase
extension = os_type == "android" ? "*.apk" : "*.ipa"
extensions = os_type == "android" ? ["*.apk", "*.aab"] : ["*.ipa"]
build_folder_path = Dir[File.expand_path('..')].first
files = []
unless options[:file].nil? || options[:file].empty?
files.push("#{build_folder_path}/#{options[:file]}")
else
files = Dir.glob("#{build_folder_path}/#{extension}").select { |f| File.file? f}
extensions.each do |extension|
files.push(Dir.glob("#{build_folder_path}/#{extension}").select { |f| File.file? f}.first)
end
end
unless ENV['AWS_BUCKET_NAME'].nil? || ENV['AWS_BUCKET_NAME'].empty? || ENV['AWS_REGION'].nil? || ENV['AWS_REGION'].empty? || files.length == 0
@ -604,7 +606,7 @@ platform :android do
replace_assets
link_sentry_android
build_android
move_apk_to_root
move_android_to_root
upload_file_to_s3({:os_type => "android"})
end
@ -735,49 +737,72 @@ platform :android do
def build_android
config_mode = ENV['BUILD_FOR_RELEASE'] == 'true' ? 'Release' : 'Debug'
build_task = ENV['ANDROID_BUILD_TASK'].nil? || ENV['ANDROID_BUILD_TASK'].empty? ? 'assemble' : ENV['ANDROID_BUILD_TASK']
build_task = build_task.split(",")
if build_task.include?("assemble")
gradle(
task: 'app:assemble',
build_type: config_mode,
project_dir: 'android/',
properties: {
'separateApk' => ENV["SEPARATE_APKS"] || false,
'universalApk' => ENV["SEPARATE_APKS"] || false,
}
)
end
gradle(
task: 'app:assemble',
build_type: config_mode,
project_dir: 'android/',
properties: {
'separateApk' => ENV["SEPARATE_APKS"] || false,
'universalApk' => ENV["SEPARATE_APKS"] || false,
}
)
if build_task.include?("bundle")
gradle(
task: 'app:bundle',
build_type: config_mode,
project_dir: 'android/',
)
end
end
def move_apk_to_root
def move_android_to_root
app_name = ENV['APP_NAME'] || 'Mattermost Beta'
app_name_sub = app_name.gsub(" ", "_")
apks = lane_context[SharedValues::GRADLE_ALL_APK_OUTPUT_PATHS]
json_path = lane_context[SharedValues::GRADLE_OUTPUT_JSON_OUTPUT_PATH]
build_task = ENV['ANDROID_BUILD_TASK'].nil? || ENV['ANDROID_BUILD_TASK'].empty? ? 'assemble' : ENV['ANDROID_BUILD_TASK']
build_task = build_task.split(",")
if json_path.nil? || json_path.empty?
dir_name = File.dirname(apks.first)
json_path = Dir.glob(File.join(dir_name, '*.json')).first
end
UI.message("JSON PATH APK #{json_path}")
outputJson = load_config_json(json_path)
paths = []
apks.each do |apk|
filename = File.basename(apk)
output = outputJson["elements"].find { |o| o["outputFile"] == filename }
unless output.nil?
filterName = output["filters"].empty? ? '' : output["filters"].first["value"]
name = "#{app_name_sub}"
unless filterName.nil? || filterName.empty?
name += "-#{filterName}"
end
new_apk_path = "#{Pathname.new(File.expand_path(File.dirname(__FILE__))).parent.to_s}/#{name}.apk"
paths.push(new_apk_path)
sh "mv #{apk} #{new_apk_path}"
UI.message("APK PATH \"#{new_apk_path}\", #{filterName}")
if build_task.include?("assemble")
apks = lane_context[SharedValues::GRADLE_ALL_APK_OUTPUT_PATHS]
json_path = lane_context[SharedValues::GRADLE_OUTPUT_JSON_OUTPUT_PATH]
if json_path.nil? || json_path.empty?
dir_name = File.dirname(apks.first)
json_path = Dir.glob(File.join(dir_name, '*.json')).first
end
UI.message("JSON PATH APK #{json_path}")
outputJson = load_config_json(json_path)
paths = []
apks.each do |apk|
filename = File.basename(apk)
output = outputJson["elements"].find { |o| o["outputFile"] == filename }
unless output.nil?
filterName = output["filters"].empty? ? '' : output["filters"].first["value"]
name = "#{app_name_sub}"
unless filterName.nil? || filterName.empty?
name += "-#{filterName}"
end
new_apk_path = "#{Pathname.new(File.expand_path(File.dirname(__FILE__))).parent.to_s}/#{name}.apk"
paths.push(new_apk_path)
sh "mv #{apk} #{new_apk_path}"
UI.message("APK PATH \"#{new_apk_path}\", #{filterName}")
end
end
lane_context[SharedValues::GRADLE_ALL_APK_OUTPUT_PATHS] = paths
end
lane_context[SharedValues::GRADLE_ALL_APK_OUTPUT_PATHS] = paths
if build_task.include?("bundle")
aab = lane_context[SharedValues::GRADLE_AAB_OUTPUT_PATH]
new_aab_path = "#{Pathname.new(File.expand_path(File.dirname(__FILE__))).parent.to_s}/#{app_name_sub}.aab"
sh "mv #{aab} #{new_aab_path}"
UI.message("AAB PATH \"#{new_aab_path}\"")
end
end
def link_sentry_android

View file

@ -12,6 +12,9 @@ export APP_SCHEME=mattermost
#export VERSION_NUMBER=
## This sets the version number ex: 210 if not set it uses the one in the code base (this one should increment always by 1 and will only update if INCREMENT_BUILD_NUMBER is true
#export BUILD_NUMBER=
## This sets the build tasks for Android. This is a comma-separated list of tasks that can have two values: 'assemble' and 'bundle'.
## If not set, it will use only the 'assemble' task. Add both values to the list if you want both apk and aab files. Example is given below
#export ANDROID_BUILD_TASK=assemble, bundle
############ MAKE GIT RESTORE THE BRANCH STATE ONCE BUILD FINISHES ############
export COMMIT_CHANGES_TO_GIT=true