简体   繁体   中英

Flutter fastlane ios how to pass --dart-define

I can't find answer for this. My app needs parameters defined --dart-define=ENVIRONMENT="$APP_ENV"<\/code>

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM