Reputation: 895
I can't find answer for this.
My app needs parameters defined --dart-define=ENVIRONMENT="$APP_ENV"
There is no problem building Android, but how to pass those while build ad-hoc in fastlane? I've prepared build scripts that run:
flutter pub get
flutter build ios --config-only \
--flavor prod \
--dart-define=ENVIRONMENT="$APP_ENV"
cd ios
bundle exec fastlane build_app_prod_ad_hoc
And my lane for fastlane is:
lane :build_app_prod_ad_hoc do
cocoapods
gym(
configuration: "AdHoc-prod",
export_method: "ad-hoc",
scheme: "prod",
export_options: {
provisioningProfiles: {
...
},
},
)
end
But I can see that my result doesn't have ENVIRONMENT set correctly. Any ideas?
Upvotes: 11
Views: 5807
Reputation: 25
I found a light solution without flavors using gitlab-ci.
flutter build ipa --build-number=$BUILD_NUMBER --dart-define="APP_ENV=$APP_ENV"
artifacts:
paths:
- build/ios/ipa/app.ipa
expire_in: 1 day
default_platform(:ios)
platform :ios do
desc "Push a new beta build to TestFlight"
lane :beta do
api_key = app_store_connect_api_key(
key_id: ENV['IOS_ID_KEY'],
issuer_id: ENV['IOS_ISSUER_ID'],
key_filepath: ENV['IOS_AUTH_KEY'],
duration: 1200,
in_house: false
)
get_certificates
get_provisioning_profile
upload_to_testflight(
ipa: '../build/ios/ipa/app.ipa' # depends on the CI current directory,
)
end
end
Next step: build app with flavor to use different bundle identifier.
Hope it helps !
Upvotes: 0
Reputation: 6761
Solution:
Encoding and replacing your dart variable in flutter_export_environment.sh and Generated.xcconfig then running the app from Xcode/Fastlane directly will work fine.
------ Details -------
The issue:
The variables passing via --dart-define won't reflect if you run the app from Xcode/ Fastlane directly without first running the flutter run/build command.
Reason:
The following generated files are involved but not intended to update manually, but in our case running from Xcode or Fastlane to build the app, the dart variables used won't get updated. When you run the flutter run or build command, these files get updated with the values from --dart-define as Base64.
/ios/Flutter/flutter_export_environment.sh
ios/Flutter/Generated.xcconfig
When you directly build the app from Xcode or use Fastlane, the Generated.xcconfig from the ios folder inside the Flutter project code is being used to run/build the app.
Example: In my case, we pass the ENV variable using --dart-define, but if you run directly from XCode without running the flutter build or run command first, these arguments won't update.
flutter run/build --flavor dev --dart-define ENV=dev
Dart define variable will store in the flutter_export_environment.sh and Generated.xcconfig in Base64 encoding.
DART_DEFINES=RU5WX1UEU9chZ2luZw==
Note: This is a workaround to avoid running the flutter run/build command followed by a Xcode/Fastlane run to solve the issue. Not the best solution, but I hope it may help someone.
Upvotes: 5