Skip to content

Instantly share code, notes, and snippets.

@jtmuller5
Last active November 7, 2024 15:58
Show Gist options
  • Save jtmuller5/49ca2e5ddb5128ba6c1301b2415df56f to your computer and use it in GitHub Desktop.
Save jtmuller5/49ca2e5ddb5128ba6c1301b2415df56f to your computer and use it in GitHub Desktop.
Android and iOS Fastfiles for Flutter App
# android/fastlane/Fastfile
update_fastlane
default_platform(:android)
platform :android do
lane :bump_version_code do
versionCode = File.read("metadata/versionCode").to_i
versionCode = versionCode + 1
f = File.new("metadata/versionCode", "w")
f.write(versionCode)
f.close
versionCode
end
desc "Deploy a new version to the Google Play"
lane :prod do
versionCode = bump_version_code
sh("flutter", "build", "appbundle", "--build-number=#{versionCode}", "--dart-define-from-file=assets/config.json")
upload_to_play_store(
track: 'production',
aab: '../build/app/outputs/bundle/release/app-release.aab',
)
send_slack_notification(message: "New production version #{versionCode} has been pushed to Google Play!")
end
desc "Deploy a new version to the beta test track of Google Play"
lane :internal do
versionCode = bump_version_code
sh("flutter", "build", "appbundle", "--build-number=#{versionCode}", "--dart-define-from-file=assets/config.json")
upload_to_play_store(
track: 'internal',
aab: '../build/app/outputs/bundle/release/app-release.aab',
)
send_slack_notification(message: "New internal version #{versionCode} has been pushed to Google Play!")
end
desc "Send a message to Slack"
lane :send_slack_notification do |options|
message = options[:message] || "A new update has been pushed!"
slack(
message: message,
success: true,
slack_url: ENV["SLACK_WEBHOOK_URL"]
)
end
end
# ios/fastlane/Fastfile
update_fastlane
default_platform(:ios)
platform :ios do
lane :bump_version_code do
versionCode = File.read("metadata/versionCode").to_i
versionCode = versionCode + 1
f = File.new("metadata/versionCode", "w")
f.write(versionCode)
f.close
versionCode
end
lane :bump_version_name do
version_name = File.read("metadata/versionName").to_i
version_name = version_name + 1
f = File.new("metadata/versionName", "w")
f.write(version_name)
f.close
version_name
end
desc "Push a new release build to the App Store"
lane :prod do
versionCode = bump_version_code
version_name = bump_version_name
sh("flutter","build","ipa","--build-name", "#{version_name}","--dart-define-from-file=assets/config.json")
upload_to_app_store(ipa: "../build/ios/ipa/myApp.ipa",
submit_for_review: true,
automatic_release: true,
force: true,
submission_information: {
"export_compliance_uses_encryption": false,
"add_id_info_uses_idfa": false}
)
send_slack_notification(message: "New production version #{versionCode} has been pushed to App Store!")
end
desc "Push a new beta build to TestFlight"
lane :beta do
versionCode = bump_version_code
version_name = bump_version_name
sh("flutter","build","ipa","--build-name", "#{version_name}","--dart-define-from-file=assets/config.json")
upload_to_testflight(ipa: "../build/ios/ipa/myApp.ipa")
send_slack_notification(message: "New internal version #{versionCode} has been pushed to TestFlight!")
end
desc "Send a message to Slack"
lane :send_slack_notification do |options|
message = options[:message] || "A new update has been pushed!"
slack(
message: message,
success: true,
slack_url: ENV["SLACK_WEBHOOK_URL"]
)
end
end
@azabcodes
Copy link

azabcodes commented Nov 7, 2024

I'm encountering an issue when running Fastlane with the following directory structure:

flutter_advanced_topics/
└── fastlane/
    ├── Fastfile
    ├── android.rb
    └── iOS.rb

The Fastfile is configured to load android.rb and iOS.rb using the following code:

Fastfile:

default_platform(:android)

# Load Android-specific lanes
eval(File.read(File.expand_path("fastlane/android.rb", __dir__)))

# Load iOS-specific lanes
eval(File.read(File.expand_path("fastlane/iOS.rb", __dir__)))

I am running the following commands:

  • For Android Production: fastlane android prod
  • For Android Internal: fastlane android internal
  • For iOS Production: fastlane ios prod
  • For iOS Internal: fastlane ios internal

However, when I try to run these commands, I get the following error:

[17:55:07]: Error accessing file, this might be due to fastlane's directory handling
Fastfile:6:in `read': No such file or directory @ rb_sysopen - /flutter_advanced_topics/fastlane/fastlane/android.rb (Errno::ENOENT)
        from Fastfile:6:in `parsing_binding'

It seems that Fastlane is incorrectly looking for the android.rb file at the path /flutter_advanced_topics/fastlane/fastlane/android.rb instead of /flutter_advanced_topics/fastlane/android.rb, which is where the file actually resides.

What I’ve tried:

  • Ensured that android.rb and iOS.rb are correctly placed inside the fastlane/ folder.
  • Verified the directory paths in Fastfile and confirmed that android.rb and iOS.rb are being loaded using the correct paths.

Expected Behavior:

Fastlane should correctly load the android.rb and iOS.rb files from the fastlane/ directory.

Environment:

  • Fastlane version: 2.225.0
  • Ruby version: 3.3.0

Can anyone help me resolve this issue? Thank you in advance!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment