Skip to content

Instantly share code, notes, and snippets.

@dafinoer
Last active October 28, 2024 06:27
Show Gist options
  • Save dafinoer/06f09a86905349e5e5cd048417d0867d to your computer and use it in GitHub Desktop.
Save dafinoer/06f09a86905349e5e5cd048417d0867d to your computer and use it in GitHub Desktop.
# This file contains the fastlane.tools configuration
# You can find the documentation at https://docs.fastlane.tools
#
# For a list of all available actions, check out
#
# https://docs.fastlane.tools/actions
#
# For a list of all available plugins, check out
#
# https://docs.fastlane.tools/plugins/available-plugins
#
# For a Firebase Distribute, you need to create [.env] file in [android] folder.
#
# Uncomment the line if you want fastlane to automatically update itself
# update_fastlane
default_platform(:android)
path_default = "build/app/outputs/flutter-apk"
platform :android do
desc "Upload a Dev Release apk to App Distribute"
lane :devRelease do
puts "Prepare Build Dev"
buildFlutterApk(prod: true, isRelease: true)
apk_path = ""
Dir.chdir("../..") do
pathRoot = Dir.pwd
apk_path = "#{pathRoot}/#{path_default}/app-dev-release.apk"
unless File.exist?(apk_path)
UI.user_error! "No Directory Apk"
end
end
firebase_app_distribution(
app: ENV["FIREBASE_ID"],
firebase_cli_token: ENV["FIREBASE_TOKEN"],
debug: true,
android_artifact_path: apk_path,
groups: "fufufafa"
)
notification(subtitle: "Finished Building", message: "APK Release Ready to in App Distribute...")
end
desc "Upload a Dev Debug apk to App Distribute"
lane :devDebug do
puts "Prepare Build Dev Debug"
buildFlutterApk(prod: false, isRelease: false)
apk_path = ""
Dir.chdir("../..") do
pathRoot = Dir.pwd
apk_path = "#{pathRoot}/#{path_default}/app-dev-debug.apk"
unless File.exist?(apk_path)
UI.user_error! "No Directory Apk"
end
end
firebase_app_distribution(
app: ENV["FIREBASE_ID"],
firebase_cli_token: ENV["FIREBASE_TOKEN"],
debug: true,
android_artifact_path: apk_path,
groups: "fufufafa"
)
notification(subtitle: "Finished Building", message: "APK Debug Ready to in App Distribute...")
end
desc "Create AAB Prod"
lane :buildAabProd do
pathProject = pathBuildProject(true)
isFvmInstalled = fvmStatus
createObfuscateFolder
obfuscate_path = ""
Dir.chdir("../..") do
obfuscate_path = "#{Dir.pwd}/obfuscate_info"
unless Dir.exist? "#{Dir.pwd}/obfuscate_info"
UI.user_error! "obfuscate_info not found"
end
end
if(isFvmInstalled)
sh("fvm", "flutter", "pub", "get", log: false)
ensure_git_status_clean(show_uncommitted_changes: true)
sh("fvm", "flutter", "build", "appbundle", "--obfuscate",
"--split-debug-info=#{obfuscate_path}",
"-t", pathProject, "--flavor", "prod",
"--release"
)
else
sh("flutter", "pub", "get", log: false)
ensure_git_status_clean(show_uncommitted_changes: true)
sh("flutter", "build", "appbundle", "--obfuscate",
"--split-debug-info=#{obfuscate_path}",
"-t", pathProject, "--flavor", "prod",
"--release"
)
end
end
private_lane :buildFlutterApk do |options|
type_file = "lib/main_dev.dart"
build_type = pathBuildProject(:prod)
flutter_keyword = fvmCheck()
is_fvm_installed = fvmStatus
release_type = "--debug"
if options[:isRelease]
release_type = "--release"
end
if is_fvm_installed
sh("fvm", "flutter", "pub", "get", log: false)
sh(
"fvm",
"flutter",
"build",
"apk",
"-t",
type_file,
"--flavor",
build_type,
release_type,
)
else
sh("flutter", "pub", "get", log: false)
sh(
"flutter",
"build",
"apk",
"-t",
type_file,
"--flavor",
build_type,
release_type,
)
end
end
private_lane :createObfuscateFolder do
is_exist_obfuscate = false
Dir.chdir("../..") do
is_exist_obfuscate = Dir.exist? "#{Dir.pwd}/obfuscate_info"
end
unless is_exist_obfuscate
puts "Create obfuscate_info folder"
Dir.chdir("../") do
sh("mkdir", "obfuscate_info")
end
else
puts "Folder obfuscate_info is exist"
end
end
def pathBuildProject(isBuildPathProd)
if(isBuildPathProd)
return "lib/main_prod.dart"
else
return "lib/main_dev.dart"
end
end
def fvmStatus
is_fvm_installed = false
Dir.chdir("../..") do
is_fvm_installed = Dir.exist? "#{Dir.pwd}/.fvm"
end
return is_fvm_installed
end
error do |exception, message|
notification(subtitle: "Failure Build #{exception}", message: "#{message}")
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment